From c9dd7298e7bdab1dec8affc6141b42ae991e65d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= <40713406+tjzel@users.noreply.github.com> Date: Wed, 29 Mar 2023 12:09:56 +0200 Subject: [PATCH] [Plugin] [1/9] Remove passing a 'method holder' object and properly use TypeScript for plugin. (#4210) ## Summary Since we are using TypeScript for plugin now we should get rid of passing the magic `t` object as a function argument and use proper imports instead. Also we no longer import whole `BabelCore` and `BabelTypes` but just the required objects. This is a direct follow up to #4209 ## Test plan `Yarn jest`, these changes don't touch plugin's logic. --- plugin/build/plugin.js | 431 +++++------------- plugin/build/plugin.js.map | 4 +- plugin/src/injectVersion.ts | 29 +- plugin/src/makeWorklet.ts | 289 ++++++------ plugin/src/plugin.ts | 35 +- ...GestureHandlerEventCallbackFunctionNode.ts | 65 ++- plugin/src/processIfWorkletNode.ts | 23 +- plugin/src/processInlineStylesWarning.ts | 116 ++--- plugin/src/processWorkletFunction.ts | 38 +- plugin/src/processWorkletObjectMethod.ts | 26 +- plugin/src/processWorklets.ts | 59 ++- plugin/src/types.ts | 4 +- 12 files changed, 476 insertions(+), 643 deletions(-) diff --git a/plugin/build/plugin.js b/plugin/build/plugin.js index 852bb7fdabf..1ebd45144c6 100644 --- a/plugin/build/plugin.js +++ b/plugin/build/plugin.js @@ -127,10 +127,9 @@ var require_makeWorklet = __commonJS({ }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.makeWorklet = void 0; - var BabelTypes = __importStar(require("@babel/types")); - var generator_1 = __importDefault(require("@babel/generator")); - var traverse_1 = __importDefault(require("@babel/traverse")); var core_1 = require("@babel/core"); + var generator_1 = __importDefault(require("@babel/generator")); + var types_1 = require("@babel/types"); var fs = __importStar(require("fs")); var convertSourceMap = __importStar(require("convert-source-map")); var utils_1 = require_utils(); @@ -155,25 +154,25 @@ var require_makeWorklet = __commonJS({ } return true; } - function buildWorkletString(t, fun, closureVariables, name, inputMap) { + function buildWorkletString(fun, closureVariables, name, inputMap) { function prependClosureVariablesIfNecessary() { - const closureDeclaration = t.variableDeclaration("const", [ - t.variableDeclarator(t.objectPattern(closureVariables.map((variable) => t.objectProperty(t.identifier(variable.name), t.identifier(variable.name), false, true))), t.memberExpression(t.thisExpression(), t.identifier("_closure"))) + const closureDeclaration = (0, types_1.variableDeclaration)("const", [ + (0, types_1.variableDeclarator)((0, types_1.objectPattern)(closureVariables.map((variable) => (0, types_1.objectProperty)((0, types_1.identifier)(variable.name), (0, types_1.identifier)(variable.name), false, true))), (0, types_1.memberExpression)((0, types_1.thisExpression)(), (0, types_1.identifier)("_closure"))) ]); function prependClosure(path) { if (closureVariables.length === 0 || path.parent.type !== "Program") { return; } - if (!BabelTypes.isExpression(path.node.body)) + if (!(0, types_1.isExpression)(path.node.body)) path.node.body.body.unshift(closureDeclaration); } function prependRecursiveDeclaration(path) { var _a; - if (path.parent.type === "Program" && !BabelTypes.isArrowFunctionExpression(path.node) && !BabelTypes.isObjectMethod(path.node) && path.node.id && path.scope.parent) { + if (path.parent.type === "Program" && !(0, types_1.isArrowFunctionExpression)(path.node) && !(0, types_1.isObjectMethod)(path.node) && path.node.id && path.scope.parent) { const hasRecursiveCalls = ((_a = path.scope.parent.bindings[path.node.id.name]) === null || _a === void 0 ? void 0 : _a.references) > 0; if (hasRecursiveCalls) { - path.node.body.body.unshift(t.variableDeclaration("const", [ - t.variableDeclarator(t.identifier(path.node.id.name), t.memberExpression(t.thisExpression(), t.identifier("_recur"))) + path.node.body.body.unshift((0, types_1.variableDeclaration)("const", [ + (0, types_1.variableDeclarator)((0, types_1.identifier)(path.node.id.name), (0, types_1.memberExpression)((0, types_1.thisExpression)(), (0, types_1.identifier)("_recur"))) ])); } } @@ -187,13 +186,13 @@ var require_makeWorklet = __commonJS({ } }; } - const draftExpression = fun.program.body.find((obj) => BabelTypes.isFunctionDeclaration(obj)) || fun.program.body.find((obj) => BabelTypes.isExpressionStatement(obj)) || void 0; + const draftExpression = fun.program.body.find((obj) => (0, types_1.isFunctionDeclaration)(obj)) || fun.program.body.find((obj) => (0, types_1.isExpressionStatement)(obj)) || void 0; if (!draftExpression) throw new Error("'draftExpression' is not defined\n"); - const expression = BabelTypes.isFunctionDeclaration(draftExpression) ? draftExpression : draftExpression.expression; - if (!("params" in expression && BabelTypes.isBlockStatement(expression.body))) + const expression = (0, types_1.isFunctionDeclaration)(draftExpression) ? draftExpression : draftExpression.expression; + if (!("params" in expression && (0, types_1.isBlockStatement)(expression.body))) throw new Error("'expression' doesn't have property 'params' or 'expression.body' is not a BlockStatmenent\n'"); - const workletFunction = BabelTypes.functionExpression(BabelTypes.identifier(name), expression.params, expression.body); + const workletFunction = (0, types_1.functionExpression)((0, types_1.identifier)(name), expression.params, expression.body); const code = (0, generator_1.default)(workletFunction).code; if (!inputMap) throw new Error("'inputMap' is not defined"); @@ -223,20 +222,20 @@ var require_makeWorklet = __commonJS({ } return [transformed.code, JSON.stringify(sourceMap)]; } - function makeWorkletName(t, fun) { - if (t.isObjectMethod(fun.node) && "name" in fun.node.key) { + function makeWorkletName(fun) { + if ((0, types_1.isObjectMethod)(fun.node) && "name" in fun.node.key) { return fun.node.key.name; } - if (t.isFunctionDeclaration(fun.node) && fun.node.id) { + if ((0, types_1.isFunctionDeclaration)(fun.node) && fun.node.id) { return fun.node.id.name; } - if (BabelTypes.isFunctionExpression(fun.node) && BabelTypes.isIdentifier(fun.node.id)) { + if ((0, types_1.isFunctionExpression)(fun.node) && (0, types_1.isIdentifier)(fun.node.id)) { return fun.node.id.name; } return "anonymous"; } - function makeWorklet(t, fun, state) { - const functionName = makeWorkletName(t, fun); + function makeWorklet(fun, state) { + const functionName = makeWorkletName(fun); const closure = /* @__PURE__ */ new Map(); fun.traverse({ DirectiveLiteral(path) { @@ -251,7 +250,7 @@ var require_makeWorklet = __commonJS({ sourceMaps: true, sourceFileName: state.file.opts.filename }); - const code = "(" + (t.isObjectMethod(fun) ? "function " : "") + codeObject.code + "\n)"; + const code = "(" + ((0, types_1.isObjectMethod)(fun) ? "function " : "") + codeObject.code + "\n)"; const transformed = (0, core_1.transformSync)(code, { filename: state.file.opts.filename, presets: ["@babel/preset-typescript"], @@ -269,12 +268,12 @@ var require_makeWorklet = __commonJS({ }); if (!transformed || !transformed.ast) throw new Error("'transformed' or 'transformed.ast' is undefined\n"); - (0, traverse_1.default)(transformed.ast, { + (0, core_1.traverse)(transformed.ast, { Identifier(path) { if (!path.isReferencedIdentifier()) return; const name = path.node.name; - if (commonObjects_12.globals.has(name) || !BabelTypes.isArrowFunctionExpression(fun.node) && !BabelTypes.isObjectMethod(fun.node) && fun.node.id && fun.node.id.name === name) { + if (commonObjects_12.globals.has(name) || !(0, types_1.isArrowFunctionExpression)(fun.node) && !(0, types_1.isObjectMethod)(fun.node) && fun.node.id && fun.node.id.name === name) { return; } const parentNode = path.parent; @@ -295,10 +294,10 @@ var require_makeWorklet = __commonJS({ } }); const variables = Array.from(closure.values()); - const privateFunctionId = t.identifier("_f"); - const clone = t.cloneNode(fun.node); - const funExpression = BabelTypes.isBlockStatement(clone.body) ? BabelTypes.functionExpression(null, clone.params, clone.body) : clone; - const [funString, sourceMapString] = buildWorkletString(t, transformed.ast, variables, functionName, transformed.map); + const privateFunctionId = (0, types_1.identifier)("_f"); + const clone = (0, types_1.cloneNode)(fun.node); + const funExpression = (0, types_1.isBlockStatement)(clone.body) ? (0, types_1.functionExpression)(null, clone.params, clone.body) : clone; + const [funString, sourceMapString] = buildWorkletString(transformed.ast, variables, functionName, transformed.map); if (!funString) throw new Error("'funString' is not defined\n"); const workletHash = hash(funString); @@ -313,38 +312,38 @@ var require_makeWorklet = __commonJS({ } const pathForStringDefinitions = fun.parentPath.isProgram() ? fun : fun.findParent((path) => path.parentPath.isProgram()); const initDataId = pathForStringDefinitions.parentPath.scope.generateUidIdentifier(`worklet_${workletHash}_init_data`); - const initDataObjectExpression = t.objectExpression([ - t.objectProperty(t.identifier("code"), t.stringLiteral(funString)), - t.objectProperty(t.identifier("location"), t.stringLiteral(location)) + const initDataObjectExpression = (0, types_1.objectExpression)([ + (0, types_1.objectProperty)((0, types_1.identifier)("code"), (0, types_1.stringLiteral)(funString)), + (0, types_1.objectProperty)((0, types_1.identifier)("location"), (0, types_1.stringLiteral)(location)) ]); if (sourceMapString) { - initDataObjectExpression.properties.push(t.objectProperty(t.identifier("sourceMap"), t.stringLiteral(sourceMapString))); + initDataObjectExpression.properties.push((0, types_1.objectProperty)((0, types_1.identifier)("sourceMap"), (0, types_1.stringLiteral)(sourceMapString))); } - pathForStringDefinitions.insertBefore(t.variableDeclaration("const", [ - t.variableDeclarator(initDataId, initDataObjectExpression) + pathForStringDefinitions.insertBefore((0, types_1.variableDeclaration)("const", [ + (0, types_1.variableDeclarator)(initDataId, initDataObjectExpression) ])); - if (BabelTypes.isFunctionDeclaration(funExpression) || BabelTypes.isObjectMethod(funExpression)) + if ((0, types_1.isFunctionDeclaration)(funExpression) || (0, types_1.isObjectMethod)(funExpression)) throw new Error("'funExpression' is either FunctionDeclaration or ObjectMethod and cannot be used in variableDeclaration\n"); const statements = [ - t.variableDeclaration("const", [ - t.variableDeclarator(privateFunctionId, funExpression) + (0, types_1.variableDeclaration)("const", [ + (0, types_1.variableDeclarator)(privateFunctionId, funExpression) ]), - t.expressionStatement(t.assignmentExpression("=", t.memberExpression(privateFunctionId, t.identifier("_closure"), false), t.objectExpression(variables.map((variable) => t.objectProperty(t.identifier(variable.name), variable, false, true))))), - t.expressionStatement(t.assignmentExpression("=", t.memberExpression(privateFunctionId, t.identifier("__initData"), false), initDataId)), - t.expressionStatement(t.assignmentExpression("=", t.memberExpression(privateFunctionId, t.identifier("__workletHash"), false), t.numericLiteral(workletHash))) + (0, types_1.expressionStatement)((0, types_1.assignmentExpression)("=", (0, types_1.memberExpression)(privateFunctionId, (0, types_1.identifier)("_closure"), false), (0, types_1.objectExpression)(variables.map((variable) => (0, types_1.objectProperty)((0, types_1.identifier)(variable.name), variable, false, true))))), + (0, types_1.expressionStatement)((0, types_1.assignmentExpression)("=", (0, types_1.memberExpression)(privateFunctionId, (0, types_1.identifier)("__initData"), false), initDataId)), + (0, types_1.expressionStatement)((0, types_1.assignmentExpression)("=", (0, types_1.memberExpression)(privateFunctionId, (0, types_1.identifier)("__workletHash"), false), (0, types_1.numericLiteral)(workletHash))) ]; if (!(0, utils_1.isRelease)()) { - statements.unshift(t.variableDeclaration("const", [ - t.variableDeclarator(t.identifier("_e"), t.arrayExpression([ - t.newExpression(t.memberExpression(t.identifier("global"), t.identifier("Error")), []), - t.numericLiteral(lineOffset), - t.numericLiteral(-27) + statements.unshift((0, types_1.variableDeclaration)("const", [ + (0, types_1.variableDeclarator)((0, types_1.identifier)("_e"), (0, types_1.arrayExpression)([ + (0, types_1.newExpression)((0, types_1.memberExpression)((0, types_1.identifier)("global"), (0, types_1.identifier)("Error")), []), + (0, types_1.numericLiteral)(lineOffset), + (0, types_1.numericLiteral)(-27) ])) ])); - statements.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(privateFunctionId, t.identifier("__stackDetails"), false), t.identifier("_e")))); + statements.push((0, types_1.expressionStatement)((0, types_1.assignmentExpression)("=", (0, types_1.memberExpression)(privateFunctionId, (0, types_1.identifier)("__stackDetails"), false), (0, types_1.identifier)("_e")))); } - statements.push(t.returnStatement(privateFunctionId)); - const newFun = t.functionExpression(void 0, [], t.blockStatement(statements)); + statements.push((0, types_1.returnStatement)(privateFunctionId)); + const newFun = (0, types_1.functionExpression)(void 0, [], (0, types_1.blockStatement)(statements)); return newFun; } exports2.makeWorklet = makeWorklet; @@ -355,47 +354,15 @@ var require_makeWorklet = __commonJS({ var require_processWorkletObjectMethod = __commonJS({ "lib/processWorkletObjectMethod.js"(exports2) { "use strict"; - var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { - return m[k]; - } }; - } - Object.defineProperty(o, k2, desc); - } : function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - o[k2] = m[k]; - }); - var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); - } : function(o, v) { - o["default"] = v; - }); - var __importStar = exports2 && exports2.__importStar || function(mod) { - if (mod && mod.__esModule) - return mod; - var result = {}; - if (mod != null) { - for (var k in mod) - if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) - __createBinding(result, mod, k); - } - __setModuleDefault(result, mod); - return result; - }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.processWorkletObjectMethod = void 0; - var BabelTypes = __importStar(require("@babel/types")); + var types_1 = require("@babel/types"); var makeWorklet_1 = require_makeWorklet(); - function processWorkletObjectMethod(t, path, state) { - if (!BabelTypes.isFunctionParent(path)) + function processWorkletObjectMethod(path, state) { + if (!(0, types_1.isFunctionParent)(path)) return; - const newFun = (0, makeWorklet_1.makeWorklet)(t, path, state); - const replacement = BabelTypes.objectProperty(BabelTypes.identifier(BabelTypes.isIdentifier(path.node.key) ? path.node.key.name : ""), t.callExpression(newFun, [])); + const newFun = (0, makeWorklet_1.makeWorklet)(path, state); + const replacement = (0, types_1.objectProperty)((0, types_1.identifier)((0, types_1.isIdentifier)(path.node.key) ? path.node.key.name : ""), (0, types_1.callExpression)(newFun, [])); path.replaceWith(replacement); } exports2.processWorkletObjectMethod = processWorkletObjectMethod; @@ -406,51 +373,19 @@ var require_processWorkletObjectMethod = __commonJS({ var require_processWorkletFunction = __commonJS({ "lib/processWorkletFunction.js"(exports2) { "use strict"; - var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { - return m[k]; - } }; - } - Object.defineProperty(o, k2, desc); - } : function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - o[k2] = m[k]; - }); - var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); - } : function(o, v) { - o["default"] = v; - }); - var __importStar = exports2 && exports2.__importStar || function(mod) { - if (mod && mod.__esModule) - return mod; - var result = {}; - if (mod != null) { - for (var k in mod) - if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) - __createBinding(result, mod, k); - } - __setModuleDefault(result, mod); - return result; - }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.processWorkletFunction = void 0; - var BabelTypes = __importStar(require("@babel/types")); + var types_1 = require("@babel/types"); var makeWorklet_1 = require_makeWorklet(); - function processWorkletFunction(t, fun, state) { - if (!t.isFunctionParent(fun)) { + function processWorkletFunction(fun, state) { + if (!(0, types_1.isFunctionParent)(fun)) { return; } - const newFun = (0, makeWorklet_1.makeWorklet)(t, fun, state); - const replacement = t.callExpression(newFun, []); - const needDeclaration = t.isScopable(fun.parent) || t.isExportNamedDeclaration(fun.parent); - fun.replaceWith(!BabelTypes.isArrowFunctionExpression(fun.node) && fun.node.id && needDeclaration ? t.variableDeclaration("const", [ - t.variableDeclarator(fun.node.id, replacement) + const newFun = (0, makeWorklet_1.makeWorklet)(fun, state); + const replacement = (0, types_1.callExpression)(newFun, []); + const needDeclaration = (0, types_1.isScopable)(fun.parent) || (0, types_1.isExportNamedDeclaration)(fun.parent); + fun.replaceWith(!(0, types_1.isArrowFunctionExpression)(fun.node) && fun.node.id && needDeclaration ? (0, types_1.variableDeclaration)("const", [ + (0, types_1.variableDeclarator)(fun.node.id, replacement) ]) : replacement); } exports2.processWorkletFunction = processWorkletFunction; @@ -461,41 +396,9 @@ var require_processWorkletFunction = __commonJS({ var require_processWorklets = __commonJS({ "lib/processWorklets.js"(exports2) { "use strict"; - var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { - return m[k]; - } }; - } - Object.defineProperty(o, k2, desc); - } : function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - o[k2] = m[k]; - }); - var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); - } : function(o, v) { - o["default"] = v; - }); - var __importStar = exports2 && exports2.__importStar || function(mod) { - if (mod && mod.__esModule) - return mod; - var result = {}; - if (mod != null) { - for (var k in mod) - if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) - __createBinding(result, mod, k); - } - __setModuleDefault(result, mod); - return result; - }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.processWorklets = void 0; - var BabelTypes = __importStar(require("@babel/types")); + var types_1 = require("@babel/types"); var processWorkletObjectMethod_1 = require_processWorkletObjectMethod(); var processWorkletFunction_1 = require_processWorkletFunction(); var functionArgsToWorkletize = /* @__PURE__ */ new Map([ @@ -516,28 +419,28 @@ var require_processWorklets = __commonJS({ "useAnimatedGestureHandler", "useAnimatedScrollHandler" ]); - function processWorklets(t, path, state) { - const callee = BabelTypes.isSequenceExpression(path.node.callee) ? path.node.callee.expressions[path.node.callee.expressions.length - 1] : path.node.callee; + function processWorklets(path, state) { + const callee = (0, types_1.isSequenceExpression)(path.node.callee) ? path.node.callee.expressions[path.node.callee.expressions.length - 1] : path.node.callee; let name = ""; if ("name" in callee) name = callee.name; else if ("property" in callee && "name" in callee.property) name = callee.property.name; - if (objectHooks.has(name) && BabelTypes.isObjectExpression(path.get("arguments.0").node)) { + if (objectHooks.has(name) && (0, types_1.isObjectExpression)(path.get("arguments.0").node)) { const properties = path.get("arguments.0.properties"); for (const property of properties) { - if (t.isObjectMethod(property.node)) { - (0, processWorkletObjectMethod_1.processWorkletObjectMethod)(t, property, state); + if ((0, types_1.isObjectMethod)(property.node)) { + (0, processWorkletObjectMethod_1.processWorkletObjectMethod)(property, state); } else { const value = property.get("value"); - (0, processWorkletFunction_1.processWorkletFunction)(t, value, state); + (0, processWorkletFunction_1.processWorkletFunction)(value, state); } } } else { const indexes = functionArgsToWorkletize.get(name); if (Array.isArray(indexes)) { indexes.forEach((index) => { - (0, processWorkletFunction_1.processWorkletFunction)(t, path.get(`arguments.${index}`), state); + (0, processWorkletFunction_1.processWorkletFunction)(path.get(`arguments.${index}`), state); }); } } @@ -550,50 +453,18 @@ var require_processWorklets = __commonJS({ var require_processIfWorkletNode = __commonJS({ "lib/processIfWorkletNode.js"(exports2) { "use strict"; - var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { - return m[k]; - } }; - } - Object.defineProperty(o, k2, desc); - } : function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - o[k2] = m[k]; - }); - var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); - } : function(o, v) { - o["default"] = v; - }); - var __importStar = exports2 && exports2.__importStar || function(mod) { - if (mod && mod.__esModule) - return mod; - var result = {}; - if (mod != null) { - for (var k in mod) - if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) - __createBinding(result, mod, k); - } - __setModuleDefault(result, mod); - return result; - }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.processIfWorkletNode = void 0; - var BabelTypes = __importStar(require("@babel/types")); + var types_1 = require("@babel/types"); var processWorkletFunction_1 = require_processWorkletFunction(); - function processIfWorkletNode(t, fun, state) { + function processIfWorkletNode(fun, state) { fun.traverse({ DirectiveLiteral(path) { const value = path.node.value; - if (value === "worklet" && path.getFunctionParent() === fun && BabelTypes.isBlockStatement(fun.node.body)) { + if (value === "worklet" && path.getFunctionParent() === fun && (0, types_1.isBlockStatement)(fun.node.body)) { const directives = fun.node.body.directives; - if (directives && directives.length > 0 && directives.some((directive) => t.isDirectiveLiteral(directive.value) && directive.value.value === "worklet")) { - (0, processWorkletFunction_1.processWorkletFunction)(t, fun, state); + if (directives && directives.length > 0 && directives.some((directive) => (0, types_1.isDirectiveLiteral)(directive.value) && directive.value.value === "worklet")) { + (0, processWorkletFunction_1.processWorkletFunction)(fun, state); } } } @@ -609,6 +480,7 @@ var require_processIfGestureHandlerEventCallbackFunctionNode = __commonJS({ "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.processIfGestureHandlerEventCallbackFunctionNode = void 0; + var types_1 = require("@babel/types"); var processWorkletFunction_1 = require_processWorkletFunction(); var gestureHandlerGestureObjects = /* @__PURE__ */ new Set([ "Tap", @@ -636,26 +508,26 @@ var require_processIfGestureHandlerEventCallbackFunctionNode = __commonJS({ "onTouchesUp", "onTouchesCancelled" ]); - function processIfGestureHandlerEventCallbackFunctionNode(t, fun, state) { - if (t.isCallExpression(fun.parent) && t.isExpression(fun.parent.callee) && isGestureObjectEventCallbackMethod(t, fun.parent.callee)) { - (0, processWorkletFunction_1.processWorkletFunction)(t, fun, state); + function processIfGestureHandlerEventCallbackFunctionNode(fun, state) { + if ((0, types_1.isCallExpression)(fun.parent) && (0, types_1.isExpression)(fun.parent.callee) && isGestureObjectEventCallbackMethod(fun.parent.callee)) { + (0, processWorkletFunction_1.processWorkletFunction)(fun, state); } } exports2.processIfGestureHandlerEventCallbackFunctionNode = processIfGestureHandlerEventCallbackFunctionNode; - function isGestureObjectEventCallbackMethod(t, node) { - return t.isMemberExpression(node) && t.isIdentifier(node.property) && gestureHandlerBuilderMethods.has(node.property.name) && containsGestureObject(t, node.object); + function isGestureObjectEventCallbackMethod(node) { + return (0, types_1.isMemberExpression)(node) && (0, types_1.isIdentifier)(node.property) && gestureHandlerBuilderMethods.has(node.property.name) && containsGestureObject(node.object); } - function containsGestureObject(t, node) { - if (isGestureObject(t, node)) { + function containsGestureObject(node) { + if (isGestureObject(node)) { return true; } - if (t.isCallExpression(node) && t.isMemberExpression(node.callee) && containsGestureObject(t, node.callee.object)) { + if ((0, types_1.isCallExpression)(node) && (0, types_1.isMemberExpression)(node.callee) && containsGestureObject(node.callee.object)) { return true; } return false; } - function isGestureObject(t, node) { - return t.isCallExpression(node) && t.isMemberExpression(node.callee) && t.isIdentifier(node.callee.object) && node.callee.object.name === "Gesture" && t.isIdentifier(node.callee.property) && gestureHandlerGestureObjects.has(node.callee.property.name); + function isGestureObject(node) { + return (0, types_1.isCallExpression)(node) && (0, types_1.isMemberExpression)(node.callee) && (0, types_1.isIdentifier)(node.callee.object) && node.callee.object.name === "Gesture" && (0, types_1.isIdentifier)(node.callee.property) && gestureHandlerGestureObjects.has(node.callee.property.name); } } }); @@ -664,103 +536,71 @@ var require_processIfGestureHandlerEventCallbackFunctionNode = __commonJS({ var require_processInlineStylesWarning = __commonJS({ "lib/processInlineStylesWarning.js"(exports2) { "use strict"; - var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { - return m[k]; - } }; - } - Object.defineProperty(o, k2, desc); - } : function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - o[k2] = m[k]; - }); - var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); - } : function(o, v) { - o["default"] = v; - }); - var __importStar = exports2 && exports2.__importStar || function(mod) { - if (mod && mod.__esModule) - return mod; - var result = {}; - if (mod != null) { - for (var k in mod) - if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) - __createBinding(result, mod, k); - } - __setModuleDefault(result, mod); - return result; - }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.processInlineStylesWarning = void 0; - var BabelTypes = __importStar(require("@babel/types")); + var types_1 = require("@babel/types"); var utils_1 = require_utils(); - function generateInlineStylesWarning(t, memberExpression) { - return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([ - t.expressionStatement(t.callExpression(t.memberExpression(t.identifier("console"), t.identifier("warn")), [ - t.callExpression(t.memberExpression(t.callExpression(t.identifier("require"), [ - t.stringLiteral("react-native-reanimated") - ]), t.identifier("getUseOfValueInStyleWarning")), []) + function generateInlineStylesWarning(path) { + return (0, types_1.callExpression)((0, types_1.arrowFunctionExpression)([], (0, types_1.blockStatement)([ + (0, types_1.expressionStatement)((0, types_1.callExpression)((0, types_1.memberExpression)((0, types_1.identifier)("console"), (0, types_1.identifier)("warn")), [ + (0, types_1.callExpression)((0, types_1.memberExpression)((0, types_1.callExpression)((0, types_1.identifier)("require"), [ + (0, types_1.stringLiteral)("react-native-reanimated") + ]), (0, types_1.identifier)("getUseOfValueInStyleWarning")), []) ])), - t.returnStatement(memberExpression.node) + (0, types_1.returnStatement)(path.node) ])), []); } - function processPropertyValueForInlineStylesWarning(t, path) { - if (t.isMemberExpression(path.node) && t.isIdentifier(path.node.property)) { + function processPropertyValueForInlineStylesWarning(path) { + if ((0, types_1.isMemberExpression)(path.node) && (0, types_1.isIdentifier)(path.node.property)) { if (path.node.property.name === "value") { - path.replaceWith(generateInlineStylesWarning(t, path)); + path.replaceWith(generateInlineStylesWarning(path)); } } } - function processTransformPropertyForInlineStylesWarning(t, path) { - if (t.isArrayExpression(path.node)) { + function processTransformPropertyForInlineStylesWarning(path) { + if ((0, types_1.isArrayExpression)(path.node)) { const elements = path.get("elements"); for (const element of elements) { - if (t.isObjectExpression(element.node)) { - processStyleObjectForInlineStylesWarning(t, element); + if ((0, types_1.isObjectExpression)(element.node)) { + processStyleObjectForInlineStylesWarning(element); } } } } - function processStyleObjectForInlineStylesWarning(t, path) { + function processStyleObjectForInlineStylesWarning(path) { const properties = path.get("properties"); for (const property of properties) { - if (!BabelTypes.isObjectProperty(property.node)) + if (!(0, types_1.isObjectProperty)(property.node)) continue; const value = property.get("value"); - if (t.isObjectProperty(property)) { - if (t.isIdentifier(property.node.key) && property.node.key.name === "transform") { - processTransformPropertyForInlineStylesWarning(t, value); + if ((0, types_1.isObjectProperty)(property)) { + if ((0, types_1.isIdentifier)(property.node.key) && property.node.key.name === "transform") { + processTransformPropertyForInlineStylesWarning(value); } else { - processPropertyValueForInlineStylesWarning(t, value); + processPropertyValueForInlineStylesWarning(value); } } } } - function processInlineStylesWarning(t, path, state) { + function processInlineStylesWarning(path, state) { if ((0, utils_1.isRelease)()) return; if (state.opts.disableInlineStylesWarning) return; if (path.node.name.name !== "style") return; - if (!t.isJSXExpressionContainer(path.node.value)) + if (!(0, types_1.isJSXExpressionContainer)(path.node.value)) return; const expression = path.get("value").get("expression"); - if (BabelTypes.isArrayExpression(expression.node)) { + if ((0, types_1.isArrayExpression)(expression.node)) { const elements = expression.get("elements"); for (const element of elements) { - if (t.isObjectExpression(element.node)) { - processStyleObjectForInlineStylesWarning(t, element); + if ((0, types_1.isObjectExpression)(element.node)) { + processStyleObjectForInlineStylesWarning(element); } } - } else if (t.isObjectExpression(expression.node)) { - processStyleObjectForInlineStylesWarning(t, expression); + } else if ((0, types_1.isObjectExpression)(expression.node)) { + processStyleObjectForInlineStylesWarning(expression); } } exports2.processInlineStylesWarning = processInlineStylesWarning; @@ -771,48 +611,16 @@ var require_processInlineStylesWarning = __commonJS({ var require_injectVersion = __commonJS({ "lib/injectVersion.js"(exports2) { "use strict"; - var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { - return m[k]; - } }; - } - Object.defineProperty(o, k2, desc); - } : function(o, m, k, k2) { - if (k2 === void 0) - k2 = k; - o[k2] = m[k]; - }); - var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); - } : function(o, v) { - o["default"] = v; - }); - var __importStar = exports2 && exports2.__importStar || function(mod) { - if (mod && mod.__esModule) - return mod; - var result = {}; - if (mod != null) { - for (var k in mod) - if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) - __createBinding(result, mod, k); - } - __setModuleDefault(result, mod); - return result; - }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.injectVersion = void 0; - var BabelTypes = __importStar(require("@babel/types")); + var types_1 = require("@babel/types"); function injectVersion(path) { if (path.node.value !== "inject Reanimated Babel plugin version") { return; } const injectedName = "_REANIMATED_VERSION_BABEL_PLUGIN"; const versionString = require("../../package.json").version; - const pluginVersionNode = BabelTypes.expressionStatement(BabelTypes.assignmentExpression("=", BabelTypes.memberExpression(BabelTypes.identifier("global"), BabelTypes.identifier(injectedName)), BabelTypes.stringLiteral(versionString))); + const pluginVersionNode = (0, types_1.expressionStatement)((0, types_1.assignmentExpression)("=", (0, types_1.memberExpression)((0, types_1.identifier)("global"), (0, types_1.identifier)(injectedName)), (0, types_1.stringLiteral)(versionString))); const functionParent = path.getFunctionParent().node; functionParent.body.directives = []; functionParent.body.body.unshift(pluginVersionNode); @@ -829,7 +637,7 @@ var processIfWorkletNode_1 = require_processIfWorkletNode(); var processIfGestureHandlerEventCallbackFunctionNode_1 = require_processIfGestureHandlerEventCallbackFunctionNode(); var processInlineStylesWarning_1 = require_processInlineStylesWarning(); var injectVersion_1 = require_injectVersion(); -function default_1({ types: t }) { +module.exports = function() { return { pre() { if (this.opts != null && Array.isArray(this.opts.globals)) { @@ -846,22 +654,21 @@ function default_1({ types: t }) { }, CallExpression: { enter(path, state) { - (0, processWorklets_1.processWorklets)(t, path, state); + (0, processWorklets_1.processWorklets)(path, state); } }, "FunctionDeclaration|FunctionExpression|ArrowFunctionExpression": { enter(path, state) { - (0, processIfWorkletNode_1.processIfWorkletNode)(t, path, state); - (0, processIfGestureHandlerEventCallbackFunctionNode_1.processIfGestureHandlerEventCallbackFunctionNode)(t, path, state); + (0, processIfWorkletNode_1.processIfWorkletNode)(path, state); + (0, processIfGestureHandlerEventCallbackFunctionNode_1.processIfGestureHandlerEventCallbackFunctionNode)(path, state); } }, JSXAttribute: { enter(path, state) { - (0, processInlineStylesWarning_1.processInlineStylesWarning)(t, path, state); + (0, processInlineStylesWarning_1.processInlineStylesWarning)(path, state); } } } }; -} -exports.default = default_1; +}; //# sourceMappingURL=plugin.js.map diff --git a/plugin/build/plugin.js.map b/plugin/build/plugin.js.map index fb09628e804..d94f6d024f2 100644 --- a/plugin/build/plugin.js.map +++ b/plugin/build/plugin.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../src/commonObjects.ts", "../src/utils.ts", "../src/makeWorklet.ts", "../src/processWorkletObjectMethod.ts", "../src/processWorkletFunction.ts", "../src/processWorklets.ts", "../src/processIfWorkletNode.ts", "../src/processIfGestureHandlerEventCallbackFunctionNode.ts", "../src/processInlineStylesWarning.ts", "../src/injectVersion.ts", "../src/plugin.ts"], - "sourcesContent": ["export const globals = new Set([\n 'this',\n 'console',\n 'performance',\n 'Date',\n 'Array',\n 'ArrayBuffer',\n 'Int8Array',\n 'Int16Array',\n 'Int32Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Uint16Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'HermesInternal',\n 'JSON',\n 'Math',\n 'Number',\n 'Object',\n 'String',\n 'Symbol',\n 'undefined',\n 'null',\n 'UIManager',\n 'requestAnimationFrame',\n 'setImmediate',\n 'queueMicrotask',\n '_WORKLET',\n 'arguments',\n 'Boolean',\n 'parseInt',\n 'parseFloat',\n 'Map',\n 'WeakMap',\n 'WeakRef',\n 'Set',\n '_log',\n '_scheduleOnJS',\n '_makeShareableClone',\n '_updateDataSynchronously',\n 'eval',\n '_updatePropsPaper',\n '_updatePropsFabric',\n '_removeShadowNodeFromRegistry',\n 'RegExp',\n 'Error',\n 'ErrorUtils',\n 'global',\n '_measure',\n '_scrollTo',\n '_dispatchCommand',\n '_setGestureState',\n '_getCurrentTime',\n 'isNaN',\n 'LayoutAnimationRepository',\n '_notifyAboutProgress',\n '_notifyAboutEnd',\n]);\n", "export function isRelease() {\n return (\n process.env.BABEL_ENV &&\n ['production', 'release'].includes(process.env.BABEL_ENV)\n );\n}\n", "import * as BabelCore from '@babel/core';\nimport * as BabelTypes from '@babel/types';\nimport generate from '@babel/generator';\nimport traverse from '@babel/traverse';\nimport { transformSync } from '@babel/core';\nimport * as fs from 'fs';\nimport * as convertSourceMap from 'convert-source-map';\nimport { ReanimatedPluginPass } from './types';\nimport { isRelease } from './utils';\nimport { globals } from './commonObjects';\n\nfunction hash(str: string): number {\n let i = str.length;\n let hash1 = 5381;\n let hash2 = 52711;\n\n while (i--) {\n const char = str.charCodeAt(i);\n hash1 = (hash1 * 33) ^ char;\n hash2 = (hash2 * 33) ^ char;\n }\n\n return (hash1 >>> 0) * 4096 + (hash2 >>> 0);\n}\n\nfunction shouldGenerateSourceMap() {\n if (isRelease()) {\n return false;\n }\n\n if (process.env.REANIMATED_PLUGIN_TESTS === 'jest') {\n // We want to detect this, so we can disable source maps (because they break\n // snapshot tests with jest).\n return false;\n }\n\n return true;\n}\n\nfunction buildWorkletString(\n t: typeof BabelCore.types,\n fun: BabelCore.types.File,\n closureVariables: Array,\n name: string,\n inputMap: BabelCore.BabelFileResult['map']\n): Array {\n function prependClosureVariablesIfNecessary() {\n const closureDeclaration = t.variableDeclaration('const', [\n t.variableDeclarator(\n t.objectPattern(\n closureVariables.map((variable) =>\n t.objectProperty(\n t.identifier(variable.name),\n t.identifier(variable.name),\n false,\n true\n )\n )\n ),\n t.memberExpression(t.thisExpression(), t.identifier('_closure'))\n ),\n ]);\n\n function prependClosure(\n path: BabelCore.NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.ObjectMethod\n >\n ) {\n if (closureVariables.length === 0 || path.parent.type !== 'Program') {\n return;\n }\n\n if (!BabelTypes.isExpression(path.node.body))\n path.node.body.body.unshift(closureDeclaration);\n }\n\n function prependRecursiveDeclaration(\n path: BabelCore.NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.ObjectMethod\n >\n ) {\n if (\n path.parent.type === 'Program' &&\n !BabelTypes.isArrowFunctionExpression(path.node) &&\n !BabelTypes.isObjectMethod(path.node) &&\n path.node.id &&\n path.scope.parent\n ) {\n const hasRecursiveCalls =\n path.scope.parent.bindings[path.node.id.name]?.references > 0;\n if (hasRecursiveCalls) {\n path.node.body.body.unshift(\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(path.node.id.name),\n t.memberExpression(t.thisExpression(), t.identifier('_recur'))\n ),\n ])\n );\n }\n }\n }\n\n return {\n visitor: {\n 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod':\n (\n path: BabelCore.NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ArrowFunctionExpression\n | BabelTypes.ObjectMethod\n >\n ) => {\n prependClosure(path);\n prependRecursiveDeclaration(path);\n },\n },\n };\n }\n\n const draftExpression = (fun.program.body.find((obj) =>\n BabelTypes.isFunctionDeclaration(obj)\n ) ||\n fun.program.body.find((obj) => BabelTypes.isExpressionStatement(obj)) ||\n undefined) as\n | BabelTypes.FunctionDeclaration\n | BabelTypes.ExpressionStatement\n | undefined;\n\n if (!draftExpression) throw new Error(\"'draftExpression' is not defined\\n\");\n\n const expression = BabelTypes.isFunctionDeclaration(draftExpression)\n ? draftExpression\n : draftExpression.expression;\n\n if (!('params' in expression && BabelTypes.isBlockStatement(expression.body)))\n throw new Error(\n \"'expression' doesn't have property 'params' or 'expression.body' is not a BlockStatmenent\\n'\"\n );\n\n const workletFunction = BabelTypes.functionExpression(\n BabelTypes.identifier(name),\n expression.params,\n expression.body\n );\n\n const code = generate(workletFunction).code;\n\n if (!inputMap) throw new Error(\"'inputMap' is not defined\");\n\n const includeSourceMap = shouldGenerateSourceMap();\n\n if (includeSourceMap) {\n // Clear contents array (should be empty anyways)\n inputMap.sourcesContent = [];\n // Include source contents in source map, because Flipper/iframe is not\n // allowed to read files from disk.\n for (const sourceFile of inputMap.sources) {\n inputMap.sourcesContent.push(\n fs.readFileSync(sourceFile).toString('utf-8')\n );\n }\n }\n\n const transformed = transformSync(code, {\n plugins: [prependClosureVariablesIfNecessary()],\n compact: !includeSourceMap,\n sourceMaps: includeSourceMap,\n inputSourceMap: inputMap,\n ast: false,\n babelrc: false,\n configFile: false,\n comments: false,\n });\n\n if (!transformed) throw new Error('transformed is null!\\n');\n\n let sourceMap;\n if (includeSourceMap) {\n sourceMap = convertSourceMap.fromObject(transformed.map).toObject();\n // sourcesContent field contains a full source code of the file which contains the worklet\n // and is not needed by the source map interpreter in order to symbolicate a stack trace.\n // Therefore, we remove it to reduce the bandwith and avoid sending it potentially multiple times\n // in files that contain multiple worklets. Along with sourcesContent.\n delete sourceMap.sourcesContent;\n }\n\n return [transformed.code, JSON.stringify(sourceMap)];\n}\n\nfunction makeWorkletName(\n t: typeof BabelCore.types,\n fun: BabelCore.NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ObjectMethod\n | BabelTypes.ArrowFunctionExpression\n >\n): string {\n if (t.isObjectMethod(fun.node) && 'name' in fun.node.key) {\n return fun.node.key.name;\n }\n if (t.isFunctionDeclaration(fun.node) && fun.node.id) {\n return fun.node.id.name;\n }\n if (\n BabelTypes.isFunctionExpression(fun.node) &&\n BabelTypes.isIdentifier(fun.node.id)\n ) {\n return fun.node.id.name;\n }\n return 'anonymous'; // fallback for ArrowFunctionExpression and unnamed FunctionExpression\n}\n\nexport function makeWorklet(\n t: typeof BabelCore.types,\n fun: BabelCore.NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ObjectMethod\n | BabelTypes.ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n): BabelTypes.FunctionExpression {\n // Returns a new FunctionExpression which is a workletized version of provided\n // FunctionDeclaration, FunctionExpression, ArrowFunctionExpression or ObjectMethod.\n\n const functionName = makeWorkletName(t, fun);\n\n const closure = new Map();\n\n // remove 'worklet'; directive before generating string\n fun.traverse({\n DirectiveLiteral(path) {\n if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {\n path.parentPath.remove();\n }\n },\n });\n\n // We use copy because some of the plugins don't update bindings and\n // some even break them\n if (!state.file.opts.filename)\n throw new Error(\"'state.file.opts.filename' is undefined\\n\");\n\n const codeObject = generate(fun.node, {\n sourceMaps: true,\n sourceFileName: state.file.opts.filename,\n });\n\n // We need to add a newline at the end, because there could potentially be a\n // comment after the function that gets included here, and then the closing\n // bracket would become part of the comment thus resulting in an error, since\n // there is a missing closing bracket.\n const code =\n '(' + (t.isObjectMethod(fun) ? 'function ' : '') + codeObject.code + '\\n)';\n\n const transformed = transformSync(code, {\n filename: state.file.opts.filename,\n presets: ['@babel/preset-typescript'],\n plugins: [\n '@babel/plugin-transform-shorthand-properties',\n '@babel/plugin-transform-arrow-functions',\n '@babel/plugin-proposal-optional-chaining',\n '@babel/plugin-proposal-nullish-coalescing-operator',\n ['@babel/plugin-transform-template-literals', { loose: true }],\n ],\n ast: true,\n babelrc: false,\n configFile: false,\n inputSourceMap: codeObject.map,\n });\n\n if (!transformed || !transformed.ast)\n throw new Error(\"'transformed' or 'transformed.ast' is undefined\\n\");\n\n traverse(transformed.ast, {\n Identifier(path) {\n if (!path.isReferencedIdentifier()) return;\n const name = path.node.name;\n if (\n globals.has(name) ||\n (!BabelTypes.isArrowFunctionExpression(fun.node) &&\n !BabelTypes.isObjectMethod(fun.node) &&\n fun.node.id &&\n fun.node.id.name === name)\n ) {\n return;\n }\n\n const parentNode = path.parent;\n\n if (\n parentNode.type === 'MemberExpression' &&\n parentNode.property === path.node &&\n !parentNode.computed\n ) {\n return;\n }\n\n if (\n parentNode.type === 'ObjectProperty' &&\n path.parentPath.parent.type === 'ObjectExpression' &&\n path.node !== parentNode.value\n ) {\n return;\n }\n\n let currentScope = path.scope;\n\n while (currentScope != null) {\n if (currentScope.bindings[name] != null) {\n return;\n }\n currentScope = currentScope.parent;\n }\n closure.set(name, path.node);\n },\n });\n\n const variables = Array.from(closure.values());\n\n const privateFunctionId = t.identifier('_f');\n const clone = t.cloneNode(fun.node);\n const funExpression = BabelTypes.isBlockStatement(clone.body)\n ? BabelTypes.functionExpression(null, clone.params, clone.body)\n : clone;\n\n const [funString, sourceMapString] = buildWorkletString(\n t,\n transformed.ast,\n variables,\n functionName,\n transformed.map\n );\n if (!funString) throw new Error(\"'funString' is not defined\\n\");\n const workletHash = hash(funString);\n\n let location = state.file.opts.filename;\n if (state.opts.relativeSourceLocation) {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const path = require('path');\n location = path.relative(state.cwd, location);\n }\n\n let lineOffset = 1;\n if (closure.size > 0) {\n // When worklet captures some variables, we append closure destructing at\n // the beginning of the function body. This effectively results in line\n // numbers shifting by the number of captured variables (size of the\n // closure) + 2 (for the opening and closing brackets of the destruct\n // statement)\n lineOffset -= closure.size + 2;\n }\n\n const pathForStringDefinitions = fun.parentPath.isProgram()\n ? fun\n : (fun.findParent(\n (path) =>\n (path.parentPath as BabelCore.NodePath).isProgram() // this causes typescript error on Windows CI build\n ) as BabelCore.NodePath); // this causes typescript error on Windows CI build\n\n const initDataId = (\n pathForStringDefinitions.parentPath as BabelCore.NodePath\n ).scope // this causes typescript error on Windows CI build\n .generateUidIdentifier(`worklet_${workletHash}_init_data`);\n\n const initDataObjectExpression = t.objectExpression([\n t.objectProperty(t.identifier('code'), t.stringLiteral(funString)),\n t.objectProperty(t.identifier('location'), t.stringLiteral(location)),\n ]);\n\n if (sourceMapString) {\n initDataObjectExpression.properties.push(\n t.objectProperty(\n t.identifier('sourceMap'),\n t.stringLiteral(sourceMapString)\n )\n );\n }\n\n pathForStringDefinitions.insertBefore(\n t.variableDeclaration('const', [\n t.variableDeclarator(initDataId, initDataObjectExpression),\n ])\n );\n\n if (\n BabelTypes.isFunctionDeclaration(funExpression) ||\n BabelTypes.isObjectMethod(funExpression)\n )\n throw new Error(\n \"'funExpression' is either FunctionDeclaration or ObjectMethod and cannot be used in variableDeclaration\\n\"\n );\n\n const statements: Array<\n | BabelTypes.VariableDeclaration\n | BabelTypes.ExpressionStatement\n | BabelTypes.ReturnStatement\n > = [\n t.variableDeclaration('const', [\n t.variableDeclarator(privateFunctionId, funExpression),\n ]),\n t.expressionStatement(\n t.assignmentExpression(\n '=',\n t.memberExpression(privateFunctionId, t.identifier('_closure'), false),\n t.objectExpression(\n variables.map((variable) =>\n t.objectProperty(t.identifier(variable.name), variable, false, true)\n )\n )\n )\n ),\n t.expressionStatement(\n t.assignmentExpression(\n '=',\n t.memberExpression(\n privateFunctionId,\n t.identifier('__initData'),\n false\n ),\n initDataId\n )\n ),\n t.expressionStatement(\n t.assignmentExpression(\n '=',\n t.memberExpression(\n privateFunctionId,\n t.identifier('__workletHash'),\n false\n ),\n t.numericLiteral(workletHash)\n )\n ),\n ];\n\n if (!isRelease()) {\n statements.unshift(\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier('_e'),\n t.arrayExpression([\n t.newExpression(\n t.memberExpression(t.identifier('global'), t.identifier('Error')),\n []\n ),\n t.numericLiteral(lineOffset),\n t.numericLiteral(-27), // the placement of opening bracket after Exception in line that defined '_e' variable\n ])\n ),\n ])\n );\n statements.push(\n t.expressionStatement(\n t.assignmentExpression(\n '=',\n t.memberExpression(\n privateFunctionId,\n t.identifier('__stackDetails'),\n false\n ),\n t.identifier('_e')\n )\n )\n );\n }\n\n statements.push(t.returnStatement(privateFunctionId));\n\n const newFun = t.functionExpression(\n // !BabelTypes.isArrowFunctionExpression(fun.node) ? fun.node.id : undefined, // [TO DO] --- this never worked\n undefined,\n [],\n t.blockStatement(statements)\n );\n\n return newFun;\n}\n", "import * as BabelCore from '@babel/core';\nimport * as BabelTypes from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { makeWorklet } from './makeWorklet';\n\nexport function processWorkletObjectMethod(\n t: typeof BabelCore.types,\n path: BabelCore.NodePath,\n state: ReanimatedPluginPass\n) {\n // Replaces ObjectMethod with a workletized version of itself.\n\n if (!BabelTypes.isFunctionParent(path)) return;\n\n const newFun = makeWorklet(t, path, state);\n\n const replacement = BabelTypes.objectProperty(\n BabelTypes.identifier(\n BabelTypes.isIdentifier(path.node.key) ? path.node.key.name : ''\n ),\n t.callExpression(newFun, [])\n );\n\n path.replaceWith(replacement);\n}\n", "import * as BabelCore from '@babel/core';\nimport * as BabelTypes from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { makeWorklet } from './makeWorklet';\n\nexport function processWorkletFunction(\n t: typeof BabelCore.types,\n fun: BabelCore.NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n) {\n // Replaces FunctionDeclaration, FunctionExpression or ArrowFunctionExpression\n // with a workletized version of itself.\n\n if (!t.isFunctionParent(fun)) {\n return;\n }\n\n const newFun = makeWorklet(t, fun, state);\n\n const replacement = t.callExpression(newFun, []);\n\n // we check if function needs to be assigned to variable declaration.\n // This is needed if function definition directly in a scope. Some other ways\n // where function definition can be used is for example with variable declaration:\n // const ggg = function foo() { }\n // ^ in such a case we don't need to define variable for the function\n const needDeclaration =\n t.isScopable(fun.parent) || t.isExportNamedDeclaration(fun.parent);\n fun.replaceWith(\n !BabelTypes.isArrowFunctionExpression(fun.node) &&\n fun.node.id &&\n needDeclaration\n ? t.variableDeclaration('const', [\n t.variableDeclarator(fun.node.id, replacement),\n ])\n : replacement\n );\n}\n", "import * as BabelCore from '@babel/core';\nimport * as BabelTypes from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { processWorkletObjectMethod } from './processWorkletObjectMethod';\nimport { processWorkletFunction } from './processWorkletFunction';\n\n/**\n * holds a map of function names as keys and array of argument indexes as values which should be automatically workletized(they have to be functions)(starting from 0)\n */\nconst functionArgsToWorkletize = new Map([\n ['useFrameCallback', [0]],\n ['useAnimatedStyle', [0]],\n ['useAnimatedProps', [0]],\n ['createAnimatedPropAdapter', [0]],\n ['useDerivedValue', [0]],\n ['useAnimatedScrollHandler', [0]],\n ['useAnimatedReaction', [0, 1]],\n ['useWorkletCallback', [0]],\n // animations' callbacks\n ['withTiming', [2]],\n ['withSpring', [2]],\n ['withDecay', [1]],\n ['withRepeat', [3]],\n]);\n\nconst objectHooks = new Set([\n 'useAnimatedGestureHandler',\n 'useAnimatedScrollHandler',\n]);\n\nexport function processWorklets(\n t: typeof BabelCore.types,\n path: BabelCore.NodePath,\n state: ReanimatedPluginPass\n) {\n const callee = BabelTypes.isSequenceExpression(path.node.callee)\n ? path.node.callee.expressions[path.node.callee.expressions.length - 1]\n : path.node.callee;\n\n let name = '';\n if ('name' in callee) name = callee.name;\n else if ('property' in callee && 'name' in callee.property)\n name = callee.property.name;\n // else name = 'anonymous'; --- might add it in the future [TO DO]\n\n if (\n objectHooks.has(name) &&\n BabelTypes.isObjectExpression(\n (\n path.get('arguments.0') as BabelCore.NodePath<\n BabelTypes.CallExpression['arguments'][number]\n >\n ).node\n )\n ) {\n const properties = path.get('arguments.0.properties') as Array<\n BabelCore.NodePath\n >;\n for (const property of properties) {\n if (t.isObjectMethod(property.node)) {\n processWorkletObjectMethod(\n t,\n property as BabelCore.NodePath,\n state\n );\n } else {\n const value = property.get('value') as BabelCore.NodePath<\n BabelTypes.ObjectProperty['value']\n >;\n processWorkletFunction(\n t,\n value as BabelCore.NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ArrowFunctionExpression\n >,\n state\n ); // temporarily given 3 types [TO DO]\n }\n }\n } else {\n const indexes = functionArgsToWorkletize.get(name);\n if (Array.isArray(indexes)) {\n indexes.forEach((index) => {\n processWorkletFunction(\n t,\n path.get(`arguments.${index}`) as BabelCore.NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ArrowFunctionExpression\n >,\n state\n ); // temporarily given 3 types [TO DO]\n });\n }\n }\n}\n", "import * as BabelCore from '@babel/core';\nimport * as BabelTypes from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { processWorkletFunction } from './processWorkletFunction';\n\nexport function processIfWorkletNode(\n t: typeof BabelCore.types,\n fun: BabelCore.NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n) {\n fun.traverse({\n DirectiveLiteral(path) {\n const value = path.node.value;\n if (\n value === 'worklet' &&\n path.getFunctionParent() === fun &&\n BabelTypes.isBlockStatement(fun.node.body)\n ) {\n // make sure \"worklet\" is listed among directives for the fun\n // this is necessary as because of some bug, babel will attempt to\n // process replaced function if it is nested inside another function\n const directives = fun.node.body.directives;\n if (\n directives &&\n directives.length > 0 &&\n directives.some(\n (directive) =>\n t.isDirectiveLiteral(directive.value) &&\n directive.value.value === 'worklet'\n )\n ) {\n processWorkletFunction(t, fun, state);\n }\n }\n },\n });\n}\n", "import * as BabelCore from '@babel/core';\nimport * as BabelTypes from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { processWorkletFunction } from './processWorkletFunction';\n\nconst gestureHandlerGestureObjects = new Set([\n // from https://github.com/software-mansion/react-native-gesture-handler/blob/new-api/src/handlers/gestures/gestureObjects.ts\n 'Tap',\n 'Pan',\n 'Pinch',\n 'Rotation',\n 'Fling',\n 'LongPress',\n 'ForceTouch',\n 'Native',\n 'Manual',\n 'Race',\n 'Simultaneous',\n 'Exclusive',\n]);\n\nconst gestureHandlerBuilderMethods = new Set([\n 'onBegin',\n 'onStart',\n 'onEnd',\n 'onFinalize',\n 'onUpdate',\n 'onChange',\n 'onTouchesDown',\n 'onTouchesMove',\n 'onTouchesUp',\n 'onTouchesCancelled',\n]);\n\nexport function processIfGestureHandlerEventCallbackFunctionNode(\n t: typeof BabelCore.types,\n fun: BabelCore.NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n) {\n // Auto-workletizes React Native Gesture Handler callback functions.\n // Detects `Gesture.Tap().onEnd()` or similar, but skips `something.onEnd()`.\n // Supports method chaining as well, e.g. `Gesture.Tap().onStart().onUpdate().onEnd()`.\n\n // Example #1: `Gesture.Tap().onEnd()`\n /*\n CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n property: Identifier('onEnd')\n )\n arguments: [fun]\n )\n */\n\n // Example #2: `Gesture.Tap().onStart().onUpdate().onEnd()`\n /*\n CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n property: Identifier('onStart')\n )\n arguments: [fun1]\n )\n property: Identifier('onUpdate')\n )\n arguments: [fun2]\n )\n property: Identifier('onEnd')\n )\n arguments: [fun3]\n )\n */\n\n if (\n t.isCallExpression(fun.parent) &&\n t.isExpression(fun.parent.callee) &&\n isGestureObjectEventCallbackMethod(t, fun.parent.callee)\n ) {\n processWorkletFunction(t, fun, state);\n }\n}\n\nfunction isGestureObjectEventCallbackMethod(\n t: typeof BabelCore.types,\n node: BabelTypes.Expression\n) {\n // Checks if node matches the pattern `Gesture.Foo()[*].onBar`\n // where `[*]` represents any number of method calls.\n return (\n t.isMemberExpression(node) &&\n t.isIdentifier(node.property) &&\n gestureHandlerBuilderMethods.has(node.property.name) &&\n containsGestureObject(t, node.object)\n );\n}\n\nfunction containsGestureObject(\n t: typeof BabelCore.types,\n node: BabelTypes.Expression\n) {\n // Checks if node matches the pattern `Gesture.Foo()[*]`\n // where `[*]` represents any number of chained method calls, like `.something(42)`.\n\n // direct call\n if (isGestureObject(t, node)) {\n return true;\n }\n\n // method chaining\n if (\n t.isCallExpression(node) &&\n t.isMemberExpression(node.callee) &&\n containsGestureObject(t, node.callee.object)\n ) {\n return true;\n }\n\n return false;\n}\n\nfunction isGestureObject(\n t: typeof BabelCore.types,\n node: BabelTypes.Expression\n) {\n // Checks if node matches `Gesture.Tap()` or similar.\n /*\n node: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n */\n return (\n t.isCallExpression(node) &&\n t.isMemberExpression(node.callee) &&\n t.isIdentifier(node.callee.object) &&\n node.callee.object.name === 'Gesture' &&\n t.isIdentifier(node.callee.property) &&\n gestureHandlerGestureObjects.has(node.callee.property.name)\n );\n}\n", "import * as BabelCore from '@babel/core';\nimport * as BabelTypes from '@babel/types';\nimport { isRelease } from './utils';\nimport { ReanimatedPluginPass } from './types';\n\nfunction generateInlineStylesWarning(\n t: typeof BabelCore.types,\n memberExpression: BabelCore.NodePath\n) {\n // replaces `sharedvalue.value` with `(()=>{console.warn(require('react-native-reanimated').getUseOfValueInStyleWarning());return sharedvalue.value;})()`\n return t.callExpression(\n t.arrowFunctionExpression(\n [],\n t.blockStatement([\n t.expressionStatement(\n t.callExpression(\n t.memberExpression(t.identifier('console'), t.identifier('warn')),\n [\n t.callExpression(\n t.memberExpression(\n t.callExpression(t.identifier('require'), [\n t.stringLiteral('react-native-reanimated'),\n ]),\n t.identifier('getUseOfValueInStyleWarning')\n ),\n []\n ),\n ]\n )\n ),\n t.returnStatement(memberExpression.node),\n ])\n ),\n []\n );\n}\n\nfunction processPropertyValueForInlineStylesWarning(\n t: typeof BabelCore.types,\n path: BabelCore.NodePath\n) {\n // if it's something like object.value then raise a warning\n if (t.isMemberExpression(path.node) && t.isIdentifier(path.node.property)) {\n if (path.node.property.name === 'value') {\n path.replaceWith(\n generateInlineStylesWarning(\n t,\n path as BabelCore.NodePath\n )\n );\n }\n }\n}\n\nfunction processTransformPropertyForInlineStylesWarning(\n t: typeof BabelCore.types,\n path: BabelCore.NodePath\n) {\n if (t.isArrayExpression(path.node)) {\n const elements = path.get('elements') as Array<\n BabelCore.NodePath\n >;\n for (const element of elements) {\n if (t.isObjectExpression(element.node)) {\n processStyleObjectForInlineStylesWarning(\n t,\n element as BabelCore.NodePath\n ); // why is it not inferred? [TO DO]\n }\n }\n }\n}\n\nfunction processStyleObjectForInlineStylesWarning(\n t: typeof BabelCore.types,\n path: BabelCore.NodePath\n) {\n const properties = path.get('properties') as Array<\n BabelCore.NodePath\n >;\n for (const property of properties) {\n if (!BabelTypes.isObjectProperty(property.node)) continue;\n const value = property.get('value') as BabelCore.NodePath<\n BabelTypes.ObjectProperty['value']\n >;\n if (t.isObjectProperty(property)) {\n if (\n t.isIdentifier(property.node.key) &&\n property.node.key.name === 'transform'\n ) {\n processTransformPropertyForInlineStylesWarning(t, value);\n } else {\n processPropertyValueForInlineStylesWarning(t, value);\n }\n }\n }\n}\n\nexport function processInlineStylesWarning(\n t: typeof BabelCore.types,\n path: BabelCore.NodePath,\n state: ReanimatedPluginPass\n) {\n if (isRelease()) return;\n if (state.opts.disableInlineStylesWarning) return;\n if (path.node.name.name !== 'style') return;\n if (!t.isJSXExpressionContainer(path.node.value)) return;\n\n const expression = path\n .get('value')\n .get('expression') as BabelCore.NodePath;\n // style={[{...}, {...}]}\n if (BabelTypes.isArrayExpression(expression.node)) {\n const elements = expression.get('elements') as Array<\n BabelCore.NodePath\n >;\n for (const element of elements) {\n if (t.isObjectExpression(element.node)) {\n processStyleObjectForInlineStylesWarning(\n t,\n element as BabelCore.NodePath\n ); // why is it not inferred? [TO DO]\n }\n }\n }\n // style={{...}}\n else if (t.isObjectExpression(expression.node)) {\n processStyleObjectForInlineStylesWarning(\n t,\n expression as BabelCore.NodePath\n ); // why is it not inferred? [TO DO]\n }\n}\n", "import * as BabelCore from '@babel/core';\nimport * as BabelTypes from '@babel/types';\n\nexport function injectVersion(\n path: BabelCore.NodePath\n) {\n // We want to inject plugin's version only once,\n // hence we have a Directive Literal line in Reanimated code.\n // See src/reanimated2/platform-specific/checkPluginVersion.ts\n // to see the details of this implementation.\n if (path.node.value !== 'inject Reanimated Babel plugin version') {\n return;\n }\n const injectedName = '_REANIMATED_VERSION_BABEL_PLUGIN';\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const versionString = require('../../package.json').version;\n const pluginVersionNode = BabelTypes.expressionStatement(\n BabelTypes.assignmentExpression(\n '=',\n BabelTypes.memberExpression(\n BabelTypes.identifier('global'),\n BabelTypes.identifier(injectedName)\n ),\n BabelTypes.stringLiteral(versionString)\n )\n );\n\n const functionParent = (\n path.getFunctionParent() as BabelCore.NodePath\n ).node;\n // DirectiveLiteral is in property of its function parent 'directives' hence we cannot just replace it.\n functionParent.body.directives = [];\n functionParent.body.body.unshift(pluginVersionNode);\n}\n", "import * as BabelCore from '@babel/core';\nimport * as BabelTypes from '@babel/types';\nimport { globals } from './commonObjects';\nimport { ReanimatedPluginPass } from './types';\nimport { processWorklets } from './processWorklets';\nimport { processIfWorkletNode } from './processIfWorkletNode';\nimport { processIfGestureHandlerEventCallbackFunctionNode } from './processIfGestureHandlerEventCallbackFunctionNode';\nimport { processInlineStylesWarning } from './processInlineStylesWarning';\nimport { injectVersion } from './injectVersion';\n\nexport default function ({ types: t }: typeof BabelCore): BabelCore.PluginItem {\n return {\n pre() {\n // allows adding custom globals such as host-functions\n if (this.opts != null && Array.isArray(this.opts.globals)) {\n this.opts.globals.forEach((name: string) => {\n globals.add(name);\n });\n }\n },\n visitor: {\n DirectiveLiteral: {\n enter(path: BabelCore.NodePath) {\n injectVersion(path);\n },\n },\n CallExpression: {\n enter(\n path: BabelCore.NodePath,\n state: ReanimatedPluginPass\n ) {\n processWorklets(t, path, state);\n },\n },\n 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression': {\n enter(\n path: BabelCore.NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.FunctionExpression\n | BabelTypes.ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n ) {\n processIfWorkletNode(t, path, state);\n processIfGestureHandlerEventCallbackFunctionNode(t, path, state);\n },\n },\n JSXAttribute: {\n enter(path, state) {\n processInlineStylesWarning(t, path, state);\n },\n },\n },\n };\n}\n"], - "mappings": ";;;;;;;;;;;;AAAa,IAAAA,SAAA,UAAU,oBAAI,IAAI;MAC7B;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;KACD;;;;;;;;;;AC3DD,aAAgB,YAAS;AACvB,aACE,QAAQ,IAAI,aACZ,CAAC,cAAc,SAAS,EAAE,SAAS,QAAQ,IAAI,SAAS;IAE5D;AALA,IAAAC,SAAA,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACCA,QAAA,aAAA,aAAA,QAAA,cAAA,CAAA;AACA,QAAA,cAAA,gBAAA,QAAA,kBAAA,CAAA;AACA,QAAA,aAAA,gBAAA,QAAA,iBAAA,CAAA;AACA,QAAA,SAAA,QAAA,aAAA;AACA,QAAA,KAAA,aAAA,QAAA,IAAA,CAAA;AACA,QAAA,mBAAA,aAAA,QAAA,oBAAA,CAAA;AAEA,QAAA,UAAA;AACA,QAAAC,mBAAA;AAEA,aAAS,KAAK,KAAW;AACvB,UAAI,IAAI,IAAI;AACZ,UAAI,QAAQ;AACZ,UAAI,QAAQ;AAEZ,aAAO,KAAK;AACV,cAAM,OAAO,IAAI,WAAW,CAAC;AAC7B,g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AAK,OAAO,GAAG;AACzD,aAAK,KAAK,QAAQ,QAAQ,CAAC,SAAgB;AACzC,0BAAA,QAAQ,IAAI,IAAI;QAClB,CAAC;;IAEL;IACA,SAAS;MACP,kBAAkB;QAChB,MAAM,MAAqD;AACzD,WAAA,GAAA,gBAAA,eAAc,IAAI;QACpB;;MAEF,gBAAgB;QACd,MACE,MACA,OAA2B;AAE3B,WAAA,GAAA,kBAAA,iBAAgB,GAAG,MAAM,KAAK;QAChC;;MAEF,kEAAkE;QAChE,MACE,MAKA,OAA2B;AAE3B,WAAA,GAAA,uBAAA,sBAAqB,GAAG,MAAM,KAAK;AACnC,WAAA,GAAA,mDAAA,kDAAiD,GAAG,MAAM,KAAK;QACjE;;MAEF,cAAc;QACZ,MAAM,MAAM,OAAK;AACf,WAAA,GAAA,6BAAA,4BAA2B,GAAG,MAAM,KAAK;QAC3C;;;;AAIR;AA5CA,QAAA,UAAA;", + "sourcesContent": ["export const globals = new Set([\n 'this',\n 'console',\n 'performance',\n 'Date',\n 'Array',\n 'ArrayBuffer',\n 'Int8Array',\n 'Int16Array',\n 'Int32Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Uint16Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'HermesInternal',\n 'JSON',\n 'Math',\n 'Number',\n 'Object',\n 'String',\n 'Symbol',\n 'undefined',\n 'null',\n 'UIManager',\n 'requestAnimationFrame',\n 'setImmediate',\n 'queueMicrotask',\n '_WORKLET',\n 'arguments',\n 'Boolean',\n 'parseInt',\n 'parseFloat',\n 'Map',\n 'WeakMap',\n 'WeakRef',\n 'Set',\n '_log',\n '_scheduleOnJS',\n '_makeShareableClone',\n '_updateDataSynchronously',\n 'eval',\n '_updatePropsPaper',\n '_updatePropsFabric',\n '_removeShadowNodeFromRegistry',\n 'RegExp',\n 'Error',\n 'ErrorUtils',\n 'global',\n '_measure',\n '_scrollTo',\n '_dispatchCommand',\n '_setGestureState',\n '_getCurrentTime',\n 'isNaN',\n 'LayoutAnimationRepository',\n '_notifyAboutProgress',\n '_notifyAboutEnd',\n]);\n", "export function isRelease() {\n return (\n process.env.BABEL_ENV &&\n ['production', 'release'].includes(process.env.BABEL_ENV)\n );\n}\n", "import {\n BabelFileResult,\n NodePath,\n transformSync,\n traverse,\n Node as BabelNode,\n} from '@babel/core';\nimport generate from '@babel/generator';\nimport {\n ObjectMethod,\n isObjectMethod,\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n identifier,\n Identifier,\n objectProperty,\n isArrowFunctionExpression,\n variableDeclaration,\n variableDeclarator,\n cloneNode,\n isBlockStatement,\n functionExpression,\n objectExpression,\n stringLiteral,\n isFunctionDeclaration,\n VariableDeclaration,\n ExpressionStatement,\n ReturnStatement,\n expressionStatement,\n assignmentExpression,\n memberExpression,\n numericLiteral,\n arrayExpression,\n newExpression,\n returnStatement,\n blockStatement,\n isFunctionExpression,\n isIdentifier,\n File as BabelTypesFile,\n objectPattern,\n thisExpression,\n isExpression,\n isExpressionStatement,\n} from '@babel/types';\nimport * as fs from 'fs';\nimport * as convertSourceMap from 'convert-source-map';\nimport { ReanimatedPluginPass } from './types';\nimport { isRelease } from './utils';\nimport { globals } from './commonObjects';\n\nfunction hash(str: string) {\n let i = str.length;\n let hash1 = 5381;\n let hash2 = 52711;\n\n while (i--) {\n const char = str.charCodeAt(i);\n hash1 = (hash1 * 33) ^ char;\n hash2 = (hash2 * 33) ^ char;\n }\n\n return (hash1 >>> 0) * 4096 + (hash2 >>> 0);\n}\n\nfunction shouldGenerateSourceMap() {\n if (isRelease()) {\n return false;\n }\n\n if (process.env.REANIMATED_PLUGIN_TESTS === 'jest') {\n // We want to detect this, so we can disable source maps (because they break\n // snapshot tests with jest).\n return false;\n }\n\n return true;\n}\n\nfunction buildWorkletString(\n fun: BabelTypesFile,\n closureVariables: Array,\n name: string,\n inputMap: BabelFileResult['map']\n): Array {\n function prependClosureVariablesIfNecessary() {\n const closureDeclaration = variableDeclaration('const', [\n variableDeclarator(\n objectPattern(\n closureVariables.map((variable) =>\n objectProperty(\n identifier(variable.name),\n identifier(variable.name),\n false,\n true\n )\n )\n ),\n memberExpression(thisExpression(), identifier('_closure'))\n ),\n ]);\n\n function prependClosure(\n path: NodePath<\n | FunctionDeclaration\n | FunctionExpression\n | ArrowFunctionExpression\n | ObjectMethod\n >\n ) {\n if (closureVariables.length === 0 || path.parent.type !== 'Program') {\n return;\n }\n\n if (!isExpression(path.node.body))\n path.node.body.body.unshift(closureDeclaration);\n }\n\n function prependRecursiveDeclaration(\n path: NodePath<\n | FunctionDeclaration\n | FunctionExpression\n | ArrowFunctionExpression\n | ObjectMethod\n >\n ) {\n if (\n path.parent.type === 'Program' &&\n !isArrowFunctionExpression(path.node) &&\n !isObjectMethod(path.node) &&\n path.node.id &&\n path.scope.parent\n ) {\n const hasRecursiveCalls =\n path.scope.parent.bindings[path.node.id.name]?.references > 0;\n if (hasRecursiveCalls) {\n path.node.body.body.unshift(\n variableDeclaration('const', [\n variableDeclarator(\n identifier(path.node.id.name),\n memberExpression(thisExpression(), identifier('_recur'))\n ),\n ])\n );\n }\n }\n }\n\n return {\n visitor: {\n 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod':\n (\n path: NodePath<\n | FunctionDeclaration\n | FunctionExpression\n | ArrowFunctionExpression\n | ObjectMethod\n >\n ) => {\n prependClosure(path);\n prependRecursiveDeclaration(path);\n },\n },\n };\n }\n\n const draftExpression = (fun.program.body.find((obj) =>\n isFunctionDeclaration(obj)\n ) ||\n fun.program.body.find((obj) => isExpressionStatement(obj)) ||\n undefined) as FunctionDeclaration | ExpressionStatement | undefined;\n\n if (!draftExpression) throw new Error(\"'draftExpression' is not defined\\n\");\n\n const expression = isFunctionDeclaration(draftExpression)\n ? draftExpression\n : draftExpression.expression;\n\n if (!('params' in expression && isBlockStatement(expression.body)))\n throw new Error(\n \"'expression' doesn't have property 'params' or 'expression.body' is not a BlockStatmenent\\n'\"\n );\n\n const workletFunction = functionExpression(\n identifier(name),\n expression.params,\n expression.body\n );\n\n const code = generate(workletFunction).code;\n\n if (!inputMap) throw new Error(\"'inputMap' is not defined\");\n\n const includeSourceMap = shouldGenerateSourceMap();\n\n if (includeSourceMap) {\n // Clear contents array (should be empty anyways)\n inputMap.sourcesContent = [];\n // Include source contents in source map, because Flipper/iframe is not\n // allowed to read files from disk.\n for (const sourceFile of inputMap.sources) {\n inputMap.sourcesContent.push(\n fs.readFileSync(sourceFile).toString('utf-8')\n );\n }\n }\n\n const transformed = transformSync(code, {\n plugins: [prependClosureVariablesIfNecessary()],\n compact: !includeSourceMap,\n sourceMaps: includeSourceMap,\n inputSourceMap: inputMap,\n ast: false,\n babelrc: false,\n configFile: false,\n comments: false,\n });\n\n if (!transformed) throw new Error('transformed is null!\\n');\n\n let sourceMap;\n if (includeSourceMap) {\n sourceMap = convertSourceMap.fromObject(transformed.map).toObject();\n // sourcesContent field contains a full source code of the file which contains the worklet\n // and is not needed by the source map interpreter in order to symbolicate a stack trace.\n // Therefore, we remove it to reduce the bandwith and avoid sending it potentially multiple times\n // in files that contain multiple worklets. Along with sourcesContent.\n delete sourceMap.sourcesContent;\n }\n\n return [transformed.code, JSON.stringify(sourceMap)];\n}\n\nfunction makeWorkletName(\n fun: NodePath<\n | FunctionDeclaration\n | FunctionExpression\n | ObjectMethod\n | ArrowFunctionExpression\n >\n) {\n if (isObjectMethod(fun.node) && 'name' in fun.node.key) {\n return fun.node.key.name;\n }\n if (isFunctionDeclaration(fun.node) && fun.node.id) {\n return fun.node.id.name;\n }\n if (isFunctionExpression(fun.node) && isIdentifier(fun.node.id)) {\n return fun.node.id.name;\n }\n return 'anonymous'; // fallback for ArrowFunctionExpression and unnamed FunctionExpression\n}\n\nexport function makeWorklet(\n fun: NodePath<\n | FunctionDeclaration\n | FunctionExpression\n | ObjectMethod\n | ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n): FunctionExpression {\n // Returns a new FunctionExpression which is a workletized version of provided\n // FunctionDeclaration, FunctionExpression, ArrowFunctionExpression or ObjectMethod.\n\n const functionName = makeWorkletName(fun);\n\n const closure = new Map();\n\n // remove 'worklet'; directive before generating string\n fun.traverse({\n DirectiveLiteral(path) {\n if (path.node.value === 'worklet' && path.getFunctionParent() === fun) {\n path.parentPath.remove();\n }\n },\n });\n\n // We use copy because some of the plugins don't update bindings and\n // some even break them\n if (!state.file.opts.filename)\n throw new Error(\"'state.file.opts.filename' is undefined\\n\");\n\n const codeObject = generate(fun.node, {\n sourceMaps: true,\n sourceFileName: state.file.opts.filename,\n });\n\n // We need to add a newline at the end, because there could potentially be a\n // comment after the function that gets included here, and then the closing\n // bracket would become part of the comment thus resulting in an error, since\n // there is a missing closing bracket.\n const code =\n '(' + (isObjectMethod(fun) ? 'function ' : '') + codeObject.code + '\\n)';\n\n const transformed = transformSync(code, {\n filename: state.file.opts.filename,\n presets: ['@babel/preset-typescript'],\n plugins: [\n '@babel/plugin-transform-shorthand-properties',\n '@babel/plugin-transform-arrow-functions',\n '@babel/plugin-proposal-optional-chaining',\n '@babel/plugin-proposal-nullish-coalescing-operator',\n ['@babel/plugin-transform-template-literals', { loose: true }],\n ],\n ast: true,\n babelrc: false,\n configFile: false,\n inputSourceMap: codeObject.map,\n });\n\n if (!transformed || !transformed.ast)\n throw new Error(\"'transformed' or 'transformed.ast' is undefined\\n\");\n\n traverse(transformed.ast, {\n Identifier(path) {\n if (!path.isReferencedIdentifier()) return;\n const name = path.node.name;\n if (\n globals.has(name) ||\n (!isArrowFunctionExpression(fun.node) &&\n !isObjectMethod(fun.node) &&\n fun.node.id &&\n fun.node.id.name === name)\n ) {\n return;\n }\n\n const parentNode = path.parent;\n\n if (\n parentNode.type === 'MemberExpression' &&\n parentNode.property === path.node &&\n !parentNode.computed\n ) {\n return;\n }\n\n if (\n parentNode.type === 'ObjectProperty' &&\n path.parentPath.parent.type === 'ObjectExpression' &&\n path.node !== parentNode.value\n ) {\n return;\n }\n\n let currentScope = path.scope;\n\n while (currentScope != null) {\n if (currentScope.bindings[name] != null) {\n return;\n }\n currentScope = currentScope.parent;\n }\n closure.set(name, path.node);\n },\n });\n\n const variables = Array.from(closure.values());\n\n const privateFunctionId = identifier('_f');\n const clone = cloneNode(fun.node);\n const funExpression = isBlockStatement(clone.body)\n ? functionExpression(null, clone.params, clone.body)\n : clone;\n\n const [funString, sourceMapString] = buildWorkletString(\n transformed.ast,\n variables,\n functionName,\n transformed.map\n );\n if (!funString) throw new Error(\"'funString' is not defined\\n\");\n const workletHash = hash(funString);\n\n let location = state.file.opts.filename;\n if (state.opts.relativeSourceLocation) {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const path = require('path');\n location = path.relative(state.cwd, location);\n }\n\n let lineOffset = 1;\n if (closure.size > 0) {\n // When worklet captures some variables, we append closure destructing at\n // the beginning of the function body. This effectively results in line\n // numbers shifting by the number of captured variables (size of the\n // closure) + 2 (for the opening and closing brackets of the destruct\n // statement)\n lineOffset -= closure.size + 2;\n }\n\n const pathForStringDefinitions = fun.parentPath.isProgram()\n ? fun\n : (fun.findParent(\n (path) => (path.parentPath as NodePath).isProgram() // lack of this 'as ...' causes typescript error on Windows CI build\n ) as NodePath); // lack of this 'as ...' this causes typescript error on Windows CI build\n\n const initDataId = (\n pathForStringDefinitions.parentPath as NodePath\n ).scope // lack of this 'as ...' this causes typescript error on Windows CI build\n .generateUidIdentifier(`worklet_${workletHash}_init_data`);\n\n const initDataObjectExpression = objectExpression([\n objectProperty(identifier('code'), stringLiteral(funString)),\n objectProperty(identifier('location'), stringLiteral(location)),\n ]);\n\n if (sourceMapString) {\n initDataObjectExpression.properties.push(\n objectProperty(identifier('sourceMap'), stringLiteral(sourceMapString))\n );\n }\n\n pathForStringDefinitions.insertBefore(\n variableDeclaration('const', [\n variableDeclarator(initDataId, initDataObjectExpression),\n ])\n );\n\n if (isFunctionDeclaration(funExpression) || isObjectMethod(funExpression))\n throw new Error(\n \"'funExpression' is either FunctionDeclaration or ObjectMethod and cannot be used in variableDeclaration\\n\"\n );\n\n const statements: Array<\n VariableDeclaration | ExpressionStatement | ReturnStatement\n > = [\n variableDeclaration('const', [\n variableDeclarator(privateFunctionId, funExpression),\n ]),\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(privateFunctionId, identifier('_closure'), false),\n objectExpression(\n variables.map((variable) =>\n objectProperty(identifier(variable.name), variable, false, true)\n )\n )\n )\n ),\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(privateFunctionId, identifier('__initData'), false),\n initDataId\n )\n ),\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(privateFunctionId, identifier('__workletHash'), false),\n numericLiteral(workletHash)\n )\n ),\n ];\n\n if (!isRelease()) {\n statements.unshift(\n variableDeclaration('const', [\n variableDeclarator(\n identifier('_e'),\n arrayExpression([\n newExpression(\n memberExpression(identifier('global'), identifier('Error')),\n []\n ),\n numericLiteral(lineOffset),\n numericLiteral(-27), // the placement of opening bracket after Exception in line that defined '_e' variable\n ])\n ),\n ])\n );\n statements.push(\n expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(\n privateFunctionId,\n identifier('__stackDetails'),\n false\n ),\n identifier('_e')\n )\n )\n );\n }\n\n statements.push(returnStatement(privateFunctionId));\n\n const newFun = functionExpression(\n // !isArrowFunctionExpression(fun.node) ? fun.node.id : undefined, // [TO DO] --- this never worked\n undefined,\n [],\n blockStatement(statements)\n );\n\n return newFun;\n}\n", "import { NodePath } from '@babel/core';\nimport {\n ObjectMethod,\n identifier,\n isIdentifier,\n isFunctionParent,\n objectProperty,\n callExpression,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { makeWorklet } from './makeWorklet';\n\nexport function processWorkletObjectMethod(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n // Replaces ObjectMethod with a workletized version of itself.\n\n if (!isFunctionParent(path)) return;\n\n const newFun = makeWorklet(path, state);\n\n const replacement = objectProperty(\n identifier(isIdentifier(path.node.key) ? path.node.key.name : ''),\n callExpression(newFun, [])\n );\n\n path.replaceWith(replacement);\n}\n", "import { NodePath } from '@babel/core';\nimport {\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n callExpression,\n isScopable,\n isExportNamedDeclaration,\n isArrowFunctionExpression,\n variableDeclaration,\n isFunctionParent,\n variableDeclarator,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { makeWorklet } from './makeWorklet';\n\nexport function processWorkletFunction(\n fun: NodePath<\n FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n) {\n // Replaces FunctionDeclaration, FunctionExpression or ArrowFunctionExpression\n // with a workletized version of itself.\n\n if (!isFunctionParent(fun)) {\n return;\n }\n\n const newFun = makeWorklet(fun, state);\n\n const replacement = callExpression(newFun, []);\n\n // we check if function needs to be assigned to variable declaration.\n // This is needed if function definition directly in a scope. Some other ways\n // where function definition can be used is for example with variable declaration:\n // const ggg = function foo() { }\n // ^ in such a case we don't need to define variable for the function\n const needDeclaration =\n isScopable(fun.parent) || isExportNamedDeclaration(fun.parent);\n fun.replaceWith(\n !isArrowFunctionExpression(fun.node) && fun.node.id && needDeclaration\n ? variableDeclaration('const', [\n variableDeclarator(fun.node.id, replacement),\n ])\n : replacement\n );\n}\n", "import { NodePath } from '@babel/core';\nimport {\n CallExpression,\n isSequenceExpression,\n isObjectExpression,\n ObjectMethod,\n ObjectProperty,\n isObjectMethod,\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { processWorkletObjectMethod } from './processWorkletObjectMethod';\nimport { processWorkletFunction } from './processWorkletFunction';\n\nconst functionArgsToWorkletize = new Map([\n ['useFrameCallback', [0]],\n ['useAnimatedStyle', [0]],\n ['useAnimatedProps', [0]],\n ['createAnimatedPropAdapter', [0]],\n ['useDerivedValue', [0]],\n ['useAnimatedScrollHandler', [0]],\n ['useAnimatedReaction', [0, 1]],\n ['useWorkletCallback', [0]],\n // animations' callbacks\n ['withTiming', [2]],\n ['withSpring', [2]],\n ['withDecay', [1]],\n ['withRepeat', [3]],\n]);\n\nconst objectHooks = new Set([\n 'useAnimatedGestureHandler',\n 'useAnimatedScrollHandler',\n]);\n\nexport function processWorklets(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n const callee = isSequenceExpression(path.node.callee)\n ? path.node.callee.expressions[path.node.callee.expressions.length - 1]\n : path.node.callee;\n\n let name = '';\n if ('name' in callee) name = callee.name;\n else if ('property' in callee && 'name' in callee.property)\n name = callee.property.name;\n // else name = 'anonymous'; --- might add it in the future [TO DO]\n\n if (\n objectHooks.has(name) &&\n isObjectExpression(\n (path.get('arguments.0') as NodePath)\n .node\n )\n ) {\n const properties = path.get('arguments.0.properties') as Array<\n NodePath\n >;\n for (const property of properties) {\n if (isObjectMethod(property.node)) {\n processWorkletObjectMethod(property as NodePath, state);\n } else {\n const value = property.get('value') as NodePath<\n ObjectProperty['value']\n >;\n processWorkletFunction(\n value as NodePath<\n FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n >,\n state\n ); // temporarily given 3 types [TO DO]\n }\n }\n } else {\n const indexes = functionArgsToWorkletize.get(name);\n if (Array.isArray(indexes)) {\n indexes.forEach((index) => {\n processWorkletFunction(\n path.get(`arguments.${index}`) as NodePath<\n FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n >,\n state\n ); // temporarily given 3 types [TO DO]\n });\n }\n }\n}\n", "import { NodePath } from '@babel/core';\nimport {\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n isBlockStatement,\n isDirectiveLiteral,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { processWorkletFunction } from './processWorkletFunction';\n\nexport function processIfWorkletNode(\n fun: NodePath<\n FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n) {\n fun.traverse({\n DirectiveLiteral(path) {\n const value = path.node.value;\n if (\n value === 'worklet' &&\n path.getFunctionParent() === fun &&\n isBlockStatement(fun.node.body)\n ) {\n // make sure \"worklet\" is listed among directives for the fun\n // this is necessary as because of some bug, babel will attempt to\n // process replaced function if it is nested inside another function\n const directives = fun.node.body.directives;\n if (\n directives &&\n directives.length > 0 &&\n directives.some(\n (directive) =>\n isDirectiveLiteral(directive.value) &&\n directive.value.value === 'worklet'\n )\n ) {\n processWorkletFunction(fun, state);\n }\n }\n },\n });\n}\n", "import { NodePath } from '@babel/core';\nimport {\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n isIdentifier,\n isCallExpression,\n Expression,\n isMemberExpression,\n isExpression,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { processWorkletFunction } from './processWorkletFunction';\n\nconst gestureHandlerGestureObjects = new Set([\n // from https://github.com/software-mansion/react-native-gesture-handler/blob/new-api/src/handlers/gestures/gestureObjects.ts\n 'Tap',\n 'Pan',\n 'Pinch',\n 'Rotation',\n 'Fling',\n 'LongPress',\n 'ForceTouch',\n 'Native',\n 'Manual',\n 'Race',\n 'Simultaneous',\n 'Exclusive',\n]);\n\nconst gestureHandlerBuilderMethods = new Set([\n 'onBegin',\n 'onStart',\n 'onEnd',\n 'onFinalize',\n 'onUpdate',\n 'onChange',\n 'onTouchesDown',\n 'onTouchesMove',\n 'onTouchesUp',\n 'onTouchesCancelled',\n]);\n\nexport function processIfGestureHandlerEventCallbackFunctionNode(\n fun: NodePath<\n FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n) {\n // Auto-workletizes React Native Gesture Handler callback functions.\n // Detects `Gesture.Tap().onEnd()` or similar, but skips `something.onEnd()`.\n // Supports method chaining as well, e.g. `Gesture.Tap().onStart().onUpdate().onEnd()`.\n\n // Example #1: `Gesture.Tap().onEnd()`\n /*\n CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n property: Identifier('onEnd')\n )\n arguments: [fun]\n )\n */\n\n // Example #2: `Gesture.Tap().onStart().onUpdate().onEnd()`\n /*\n CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n property: Identifier('onStart')\n )\n arguments: [fun1]\n )\n property: Identifier('onUpdate')\n )\n arguments: [fun2]\n )\n property: Identifier('onEnd')\n )\n arguments: [fun3]\n )\n */\n\n if (\n isCallExpression(fun.parent) &&\n isExpression(fun.parent.callee) &&\n isGestureObjectEventCallbackMethod(fun.parent.callee)\n ) {\n processWorkletFunction(fun, state);\n }\n}\n\nfunction isGestureObjectEventCallbackMethod(node: Expression) {\n // Checks if node matches the pattern `Gesture.Foo()[*].onBar`\n // where `[*]` represents any number of method calls.\n return (\n isMemberExpression(node) &&\n isIdentifier(node.property) &&\n gestureHandlerBuilderMethods.has(node.property.name) &&\n containsGestureObject(node.object)\n );\n}\n\nfunction containsGestureObject(node: Expression) {\n // Checks if node matches the pattern `Gesture.Foo()[*]`\n // where `[*]` represents any number of chained method calls, like `.something(42)`.\n\n // direct call\n if (isGestureObject(node)) {\n return true;\n }\n\n // method chaining\n if (\n isCallExpression(node) &&\n isMemberExpression(node.callee) &&\n containsGestureObject(node.callee.object)\n ) {\n return true;\n }\n\n return false;\n}\n\nfunction isGestureObject(node: Expression) {\n // Checks if node matches `Gesture.Tap()` or similar.\n /*\n node: CallExpression(\n callee: MemberExpression(\n object: Identifier('Gesture')\n property: Identifier('Tap')\n )\n )\n */\n return (\n isCallExpression(node) &&\n isMemberExpression(node.callee) &&\n isIdentifier(node.callee.object) &&\n node.callee.object.name === 'Gesture' &&\n isIdentifier(node.callee.property) &&\n gestureHandlerGestureObjects.has(node.callee.property.name)\n );\n}\n", "import { NodePath } from '@babel/core';\nimport {\n MemberExpression,\n callExpression,\n arrowFunctionExpression,\n isMemberExpression,\n isArrayExpression,\n isObjectExpression,\n ArrayExpression,\n ObjectExpression,\n isObjectProperty,\n JSXAttribute,\n isJSXExpressionContainer,\n Expression,\n identifier,\n stringLiteral,\n expressionStatement,\n memberExpression,\n returnStatement,\n blockStatement,\n ObjectProperty,\n isIdentifier,\n} from '@babel/types';\nimport { isRelease } from './utils';\nimport { ReanimatedPluginPass } from './types';\n\nfunction generateInlineStylesWarning(path: NodePath) {\n // replaces `sharedvalue.value` with `(()=>{console.warn(require('react-native-reanimated').getUseOfValueInStyleWarning());return sharedvalue.value;})()`\n return callExpression(\n arrowFunctionExpression(\n [],\n blockStatement([\n expressionStatement(\n callExpression(\n memberExpression(identifier('console'), identifier('warn')),\n [\n callExpression(\n memberExpression(\n callExpression(identifier('require'), [\n stringLiteral('react-native-reanimated'),\n ]),\n identifier('getUseOfValueInStyleWarning')\n ),\n []\n ),\n ]\n )\n ),\n returnStatement(path.node),\n ])\n ),\n []\n );\n}\n\nfunction processPropertyValueForInlineStylesWarning(\n path: NodePath\n) {\n // if it's something like object.value then raise a warning\n if (isMemberExpression(path.node) && isIdentifier(path.node.property)) {\n if (path.node.property.name === 'value') {\n path.replaceWith(\n generateInlineStylesWarning(path as NodePath)\n );\n }\n }\n}\n\nfunction processTransformPropertyForInlineStylesWarning(\n path: NodePath\n) {\n if (isArrayExpression(path.node)) {\n const elements = path.get('elements') as Array<\n NodePath\n >;\n for (const element of elements) {\n if (isObjectExpression(element.node)) {\n processStyleObjectForInlineStylesWarning(\n element as NodePath\n ); // why is it not inferred? [TO DO]\n }\n }\n }\n}\n\nfunction processStyleObjectForInlineStylesWarning(\n path: NodePath\n) {\n const properties = path.get('properties') as Array<\n NodePath\n >;\n for (const property of properties) {\n if (!isObjectProperty(property.node)) continue;\n const value = property.get('value') as NodePath;\n if (isObjectProperty(property)) {\n if (\n isIdentifier(property.node.key) &&\n property.node.key.name === 'transform'\n ) {\n processTransformPropertyForInlineStylesWarning(value);\n } else {\n processPropertyValueForInlineStylesWarning(value);\n }\n }\n }\n}\n\nexport function processInlineStylesWarning(\n path: NodePath,\n state: ReanimatedPluginPass\n) {\n if (isRelease()) return;\n if (state.opts.disableInlineStylesWarning) return;\n if (path.node.name.name !== 'style') return;\n if (!isJSXExpressionContainer(path.node.value)) return;\n\n const expression = path\n .get('value')\n .get('expression') as NodePath;\n // style={[{...}, {...}]}\n if (isArrayExpression(expression.node)) {\n const elements = expression.get('elements') as Array<\n NodePath\n >;\n for (const element of elements) {\n if (isObjectExpression(element.node)) {\n processStyleObjectForInlineStylesWarning(\n element as NodePath\n ); // why is it not inferred? [TO DO]\n }\n }\n }\n // style={{...}}\n else if (isObjectExpression(expression.node)) {\n processStyleObjectForInlineStylesWarning(\n expression as NodePath\n ); // why is it not inferred? [TO DO]\n }\n}\n", "import { NodePath } from '@babel/core';\nimport {\n DirectiveLiteral,\n expressionStatement,\n assignmentExpression,\n memberExpression,\n identifier,\n stringLiteral,\n FunctionDeclaration,\n} from '@babel/types';\n\nexport function injectVersion(path: NodePath) {\n // We want to inject plugin's version only once,\n // hence we have a Directive Literal line in Reanimated code.\n // See src/reanimated2/platform-specific/checkPluginVersion.ts\n // to see the details of this implementation.\n if (path.node.value !== 'inject Reanimated Babel plugin version') {\n return;\n }\n const injectedName = '_REANIMATED_VERSION_BABEL_PLUGIN';\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const versionString = require('../../package.json').version;\n const pluginVersionNode = expressionStatement(\n assignmentExpression(\n '=',\n memberExpression(identifier('global'), identifier(injectedName)),\n stringLiteral(versionString)\n )\n );\n\n const functionParent = (\n path.getFunctionParent() as NodePath\n ).node;\n // DirectiveLiteral is in property of its function parent 'directives' hence we cannot just replace it.\n functionParent.body.directives = [];\n functionParent.body.body.unshift(pluginVersionNode);\n}\n", "import { PluginItem, NodePath } from '@babel/core';\nimport { globals } from './commonObjects';\nimport {\n CallExpression,\n FunctionDeclaration,\n FunctionExpression,\n ArrowFunctionExpression,\n DirectiveLiteral,\n} from '@babel/types';\nimport { ReanimatedPluginPass } from './types';\nimport { processWorklets } from './processWorklets';\nimport { processIfWorkletNode } from './processIfWorkletNode';\nimport { processIfGestureHandlerEventCallbackFunctionNode } from './processIfGestureHandlerEventCallbackFunctionNode';\nimport { processInlineStylesWarning } from './processInlineStylesWarning';\nimport { injectVersion } from './injectVersion';\n\nmodule.exports = function (): PluginItem {\n return {\n pre() {\n // allows adding custom globals such as host-functions\n if (this.opts != null && Array.isArray(this.opts.globals)) {\n this.opts.globals.forEach((name: string) => {\n globals.add(name);\n });\n }\n },\n visitor: {\n DirectiveLiteral: {\n enter(path: NodePath) {\n injectVersion(path);\n },\n },\n CallExpression: {\n enter(path: NodePath, state: ReanimatedPluginPass) {\n processWorklets(path, state);\n },\n },\n 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression': {\n enter(\n path: NodePath<\n FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n >,\n state: ReanimatedPluginPass\n ) {\n processIfWorkletNode(path, state);\n processIfGestureHandlerEventCallbackFunctionNode(path, state);\n },\n },\n JSXAttribute: {\n enter(path, state) {\n processInlineStylesWarning(path, state);\n },\n },\n },\n };\n};\n"], + "mappings": ";;;;;;;;;;;;AAAa,IAAAA,SAAA,UAAU,oBAAI,IAAI;MAC7B;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;KACD;;;;;;;;;;AC3DD,aAAgB,YAAS;AACvB,aACE,QAAQ,IAAI,aACZ,CAAC,cAAc,SAAS,EAAE,SAAS,QAAQ,IAAI,SAAS;IAE5D;AALA,IAAAC,SAAA,YAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAA,mDAAA,kDAAiD,MAAM,KAAK;QAC9D;;MAEF,cAAc;QACZ,MAAM,MAAM,OAAK;AACf,WAAA,GAAA,6BAAA,4BAA2B,MAAM,KAAK;QACxC;;;;AAIR;", "names": ["exports", "exports", "commonObjects_1", "exports", "exports", "exports", "exports", "exports", "exports", "exports", "exports"] } diff --git a/plugin/src/injectVersion.ts b/plugin/src/injectVersion.ts index 577b26dce9e..913690d97f3 100644 --- a/plugin/src/injectVersion.ts +++ b/plugin/src/injectVersion.ts @@ -1,9 +1,15 @@ -import * as BabelCore from '@babel/core'; -import * as BabelTypes from '@babel/types'; +import { NodePath } from '@babel/core'; +import { + DirectiveLiteral, + expressionStatement, + assignmentExpression, + memberExpression, + identifier, + stringLiteral, + FunctionDeclaration, +} from '@babel/types'; -export function injectVersion( - path: BabelCore.NodePath -) { +export function injectVersion(path: NodePath) { // We want to inject plugin's version only once, // hence we have a Directive Literal line in Reanimated code. // See src/reanimated2/platform-specific/checkPluginVersion.ts @@ -14,19 +20,16 @@ export function injectVersion( const injectedName = '_REANIMATED_VERSION_BABEL_PLUGIN'; // eslint-disable-next-line @typescript-eslint/no-var-requires const versionString = require('../../package.json').version; - const pluginVersionNode = BabelTypes.expressionStatement( - BabelTypes.assignmentExpression( + const pluginVersionNode = expressionStatement( + assignmentExpression( '=', - BabelTypes.memberExpression( - BabelTypes.identifier('global'), - BabelTypes.identifier(injectedName) - ), - BabelTypes.stringLiteral(versionString) + memberExpression(identifier('global'), identifier(injectedName)), + stringLiteral(versionString) ) ); const functionParent = ( - path.getFunctionParent() as BabelCore.NodePath + path.getFunctionParent() as NodePath ).node; // DirectiveLiteral is in property of its function parent 'directives' hence we cannot just replace it. functionParent.body.directives = []; diff --git a/plugin/src/makeWorklet.ts b/plugin/src/makeWorklet.ts index 7d9728e66ef..4083ee91433 100644 --- a/plugin/src/makeWorklet.ts +++ b/plugin/src/makeWorklet.ts @@ -1,15 +1,55 @@ -import * as BabelCore from '@babel/core'; -import * as BabelTypes from '@babel/types'; +import { + BabelFileResult, + NodePath, + transformSync, + traverse, + Node as BabelNode, +} from '@babel/core'; import generate from '@babel/generator'; -import traverse from '@babel/traverse'; -import { transformSync } from '@babel/core'; +import { + ObjectMethod, + isObjectMethod, + FunctionDeclaration, + FunctionExpression, + ArrowFunctionExpression, + identifier, + Identifier, + objectProperty, + isArrowFunctionExpression, + variableDeclaration, + variableDeclarator, + cloneNode, + isBlockStatement, + functionExpression, + objectExpression, + stringLiteral, + isFunctionDeclaration, + VariableDeclaration, + ExpressionStatement, + ReturnStatement, + expressionStatement, + assignmentExpression, + memberExpression, + numericLiteral, + arrayExpression, + newExpression, + returnStatement, + blockStatement, + isFunctionExpression, + isIdentifier, + File as BabelTypesFile, + objectPattern, + thisExpression, + isExpression, + isExpressionStatement, +} from '@babel/types'; import * as fs from 'fs'; import * as convertSourceMap from 'convert-source-map'; import { ReanimatedPluginPass } from './types'; import { isRelease } from './utils'; import { globals } from './commonObjects'; -function hash(str: string): number { +function hash(str: string) { let i = str.length; let hash1 = 5381; let hash2 = 52711; @@ -38,57 +78,56 @@ function shouldGenerateSourceMap() { } function buildWorkletString( - t: typeof BabelCore.types, - fun: BabelCore.types.File, - closureVariables: Array, + fun: BabelTypesFile, + closureVariables: Array, name: string, - inputMap: BabelCore.BabelFileResult['map'] + inputMap: BabelFileResult['map'] ): Array { function prependClosureVariablesIfNecessary() { - const closureDeclaration = t.variableDeclaration('const', [ - t.variableDeclarator( - t.objectPattern( + const closureDeclaration = variableDeclaration('const', [ + variableDeclarator( + objectPattern( closureVariables.map((variable) => - t.objectProperty( - t.identifier(variable.name), - t.identifier(variable.name), + objectProperty( + identifier(variable.name), + identifier(variable.name), false, true ) ) ), - t.memberExpression(t.thisExpression(), t.identifier('_closure')) + memberExpression(thisExpression(), identifier('_closure')) ), ]); function prependClosure( - path: BabelCore.NodePath< - | BabelTypes.FunctionDeclaration - | BabelTypes.FunctionExpression - | BabelTypes.ArrowFunctionExpression - | BabelTypes.ObjectMethod + path: NodePath< + | FunctionDeclaration + | FunctionExpression + | ArrowFunctionExpression + | ObjectMethod > ) { if (closureVariables.length === 0 || path.parent.type !== 'Program') { return; } - if (!BabelTypes.isExpression(path.node.body)) + if (!isExpression(path.node.body)) path.node.body.body.unshift(closureDeclaration); } function prependRecursiveDeclaration( - path: BabelCore.NodePath< - | BabelTypes.FunctionDeclaration - | BabelTypes.FunctionExpression - | BabelTypes.ArrowFunctionExpression - | BabelTypes.ObjectMethod + path: NodePath< + | FunctionDeclaration + | FunctionExpression + | ArrowFunctionExpression + | ObjectMethod > ) { if ( path.parent.type === 'Program' && - !BabelTypes.isArrowFunctionExpression(path.node) && - !BabelTypes.isObjectMethod(path.node) && + !isArrowFunctionExpression(path.node) && + !isObjectMethod(path.node) && path.node.id && path.scope.parent ) { @@ -96,10 +135,10 @@ function buildWorkletString( path.scope.parent.bindings[path.node.id.name]?.references > 0; if (hasRecursiveCalls) { path.node.body.body.unshift( - t.variableDeclaration('const', [ - t.variableDeclarator( - t.identifier(path.node.id.name), - t.memberExpression(t.thisExpression(), t.identifier('_recur')) + variableDeclaration('const', [ + variableDeclarator( + identifier(path.node.id.name), + memberExpression(thisExpression(), identifier('_recur')) ), ]) ); @@ -111,11 +150,11 @@ function buildWorkletString( visitor: { 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression|ObjectMethod': ( - path: BabelCore.NodePath< - | BabelTypes.FunctionDeclaration - | BabelTypes.FunctionExpression - | BabelTypes.ArrowFunctionExpression - | BabelTypes.ObjectMethod + path: NodePath< + | FunctionDeclaration + | FunctionExpression + | ArrowFunctionExpression + | ObjectMethod > ) => { prependClosure(path); @@ -126,27 +165,24 @@ function buildWorkletString( } const draftExpression = (fun.program.body.find((obj) => - BabelTypes.isFunctionDeclaration(obj) + isFunctionDeclaration(obj) ) || - fun.program.body.find((obj) => BabelTypes.isExpressionStatement(obj)) || - undefined) as - | BabelTypes.FunctionDeclaration - | BabelTypes.ExpressionStatement - | undefined; + fun.program.body.find((obj) => isExpressionStatement(obj)) || + undefined) as FunctionDeclaration | ExpressionStatement | undefined; if (!draftExpression) throw new Error("'draftExpression' is not defined\n"); - const expression = BabelTypes.isFunctionDeclaration(draftExpression) + const expression = isFunctionDeclaration(draftExpression) ? draftExpression : draftExpression.expression; - if (!('params' in expression && BabelTypes.isBlockStatement(expression.body))) + if (!('params' in expression && isBlockStatement(expression.body))) throw new Error( "'expression' doesn't have property 'params' or 'expression.body' is not a BlockStatmenent\n'" ); - const workletFunction = BabelTypes.functionExpression( - BabelTypes.identifier(name), + const workletFunction = functionExpression( + identifier(name), expression.params, expression.body ); @@ -196,45 +232,40 @@ function buildWorkletString( } function makeWorkletName( - t: typeof BabelCore.types, - fun: BabelCore.NodePath< - | BabelTypes.FunctionDeclaration - | BabelTypes.FunctionExpression - | BabelTypes.ObjectMethod - | BabelTypes.ArrowFunctionExpression + fun: NodePath< + | FunctionDeclaration + | FunctionExpression + | ObjectMethod + | ArrowFunctionExpression > -): string { - if (t.isObjectMethod(fun.node) && 'name' in fun.node.key) { +) { + if (isObjectMethod(fun.node) && 'name' in fun.node.key) { return fun.node.key.name; } - if (t.isFunctionDeclaration(fun.node) && fun.node.id) { + if (isFunctionDeclaration(fun.node) && fun.node.id) { return fun.node.id.name; } - if ( - BabelTypes.isFunctionExpression(fun.node) && - BabelTypes.isIdentifier(fun.node.id) - ) { + if (isFunctionExpression(fun.node) && isIdentifier(fun.node.id)) { return fun.node.id.name; } return 'anonymous'; // fallback for ArrowFunctionExpression and unnamed FunctionExpression } export function makeWorklet( - t: typeof BabelCore.types, - fun: BabelCore.NodePath< - | BabelTypes.FunctionDeclaration - | BabelTypes.FunctionExpression - | BabelTypes.ObjectMethod - | BabelTypes.ArrowFunctionExpression + fun: NodePath< + | FunctionDeclaration + | FunctionExpression + | ObjectMethod + | ArrowFunctionExpression >, state: ReanimatedPluginPass -): BabelTypes.FunctionExpression { +): FunctionExpression { // Returns a new FunctionExpression which is a workletized version of provided // FunctionDeclaration, FunctionExpression, ArrowFunctionExpression or ObjectMethod. - const functionName = makeWorkletName(t, fun); + const functionName = makeWorkletName(fun); - const closure = new Map(); + const closure = new Map(); // remove 'worklet'; directive before generating string fun.traverse({ @@ -260,7 +291,7 @@ export function makeWorklet( // bracket would become part of the comment thus resulting in an error, since // there is a missing closing bracket. const code = - '(' + (t.isObjectMethod(fun) ? 'function ' : '') + codeObject.code + '\n)'; + '(' + (isObjectMethod(fun) ? 'function ' : '') + codeObject.code + '\n)'; const transformed = transformSync(code, { filename: state.file.opts.filename, @@ -287,8 +318,8 @@ export function makeWorklet( const name = path.node.name; if ( globals.has(name) || - (!BabelTypes.isArrowFunctionExpression(fun.node) && - !BabelTypes.isObjectMethod(fun.node) && + (!isArrowFunctionExpression(fun.node) && + !isObjectMethod(fun.node) && fun.node.id && fun.node.id.name === name) ) { @@ -327,14 +358,13 @@ export function makeWorklet( const variables = Array.from(closure.values()); - const privateFunctionId = t.identifier('_f'); - const clone = t.cloneNode(fun.node); - const funExpression = BabelTypes.isBlockStatement(clone.body) - ? BabelTypes.functionExpression(null, clone.params, clone.body) + const privateFunctionId = identifier('_f'); + const clone = cloneNode(fun.node); + const funExpression = isBlockStatement(clone.body) + ? functionExpression(null, clone.params, clone.body) : clone; const [funString, sourceMapString] = buildWorkletString( - t, transformed.ast, variables, functionName, @@ -363,124 +393,107 @@ export function makeWorklet( const pathForStringDefinitions = fun.parentPath.isProgram() ? fun : (fun.findParent( - (path) => - (path.parentPath as BabelCore.NodePath).isProgram() // this causes typescript error on Windows CI build - ) as BabelCore.NodePath); // this causes typescript error on Windows CI build + (path) => (path.parentPath as NodePath).isProgram() // lack of this 'as ...' causes typescript error on Windows CI build + ) as NodePath); // lack of this 'as ...' this causes typescript error on Windows CI build const initDataId = ( - pathForStringDefinitions.parentPath as BabelCore.NodePath - ).scope // this causes typescript error on Windows CI build + pathForStringDefinitions.parentPath as NodePath + ).scope // lack of this 'as ...' this causes typescript error on Windows CI build .generateUidIdentifier(`worklet_${workletHash}_init_data`); - const initDataObjectExpression = t.objectExpression([ - t.objectProperty(t.identifier('code'), t.stringLiteral(funString)), - t.objectProperty(t.identifier('location'), t.stringLiteral(location)), + const initDataObjectExpression = objectExpression([ + objectProperty(identifier('code'), stringLiteral(funString)), + objectProperty(identifier('location'), stringLiteral(location)), ]); if (sourceMapString) { initDataObjectExpression.properties.push( - t.objectProperty( - t.identifier('sourceMap'), - t.stringLiteral(sourceMapString) - ) + objectProperty(identifier('sourceMap'), stringLiteral(sourceMapString)) ); } pathForStringDefinitions.insertBefore( - t.variableDeclaration('const', [ - t.variableDeclarator(initDataId, initDataObjectExpression), + variableDeclaration('const', [ + variableDeclarator(initDataId, initDataObjectExpression), ]) ); - if ( - BabelTypes.isFunctionDeclaration(funExpression) || - BabelTypes.isObjectMethod(funExpression) - ) + if (isFunctionDeclaration(funExpression) || isObjectMethod(funExpression)) throw new Error( "'funExpression' is either FunctionDeclaration or ObjectMethod and cannot be used in variableDeclaration\n" ); const statements: Array< - | BabelTypes.VariableDeclaration - | BabelTypes.ExpressionStatement - | BabelTypes.ReturnStatement + VariableDeclaration | ExpressionStatement | ReturnStatement > = [ - t.variableDeclaration('const', [ - t.variableDeclarator(privateFunctionId, funExpression), + variableDeclaration('const', [ + variableDeclarator(privateFunctionId, funExpression), ]), - t.expressionStatement( - t.assignmentExpression( + expressionStatement( + assignmentExpression( '=', - t.memberExpression(privateFunctionId, t.identifier('_closure'), false), - t.objectExpression( + memberExpression(privateFunctionId, identifier('_closure'), false), + objectExpression( variables.map((variable) => - t.objectProperty(t.identifier(variable.name), variable, false, true) + objectProperty(identifier(variable.name), variable, false, true) ) ) ) ), - t.expressionStatement( - t.assignmentExpression( + expressionStatement( + assignmentExpression( '=', - t.memberExpression( - privateFunctionId, - t.identifier('__initData'), - false - ), + memberExpression(privateFunctionId, identifier('__initData'), false), initDataId ) ), - t.expressionStatement( - t.assignmentExpression( + expressionStatement( + assignmentExpression( '=', - t.memberExpression( - privateFunctionId, - t.identifier('__workletHash'), - false - ), - t.numericLiteral(workletHash) + memberExpression(privateFunctionId, identifier('__workletHash'), false), + numericLiteral(workletHash) ) ), ]; if (!isRelease()) { statements.unshift( - t.variableDeclaration('const', [ - t.variableDeclarator( - t.identifier('_e'), - t.arrayExpression([ - t.newExpression( - t.memberExpression(t.identifier('global'), t.identifier('Error')), + variableDeclaration('const', [ + variableDeclarator( + identifier('_e'), + arrayExpression([ + newExpression( + memberExpression(identifier('global'), identifier('Error')), [] ), - t.numericLiteral(lineOffset), - t.numericLiteral(-27), // the placement of opening bracket after Exception in line that defined '_e' variable + numericLiteral(lineOffset), + numericLiteral(-27), // the placement of opening bracket after Exception in line that defined '_e' variable ]) ), ]) ); statements.push( - t.expressionStatement( - t.assignmentExpression( + expressionStatement( + assignmentExpression( '=', - t.memberExpression( + memberExpression( privateFunctionId, - t.identifier('__stackDetails'), + identifier('__stackDetails'), false ), - t.identifier('_e') + identifier('_e') ) ) ); } - statements.push(t.returnStatement(privateFunctionId)); + statements.push(returnStatement(privateFunctionId)); - const newFun = t.functionExpression( - // !BabelTypes.isArrowFunctionExpression(fun.node) ? fun.node.id : undefined, // [TO DO] --- this never worked + const newFun = functionExpression( + // !isArrowFunctionExpression(fun.node) ? fun.node.id : undefined, // [TO DO] --- this never worked undefined, [], - t.blockStatement(statements) + blockStatement(statements) ); return newFun; diff --git a/plugin/src/plugin.ts b/plugin/src/plugin.ts index 682c07fc61e..278a763c4a0 100644 --- a/plugin/src/plugin.ts +++ b/plugin/src/plugin.ts @@ -1,6 +1,12 @@ -import * as BabelCore from '@babel/core'; -import * as BabelTypes from '@babel/types'; +import { PluginItem, NodePath } from '@babel/core'; import { globals } from './commonObjects'; +import { + CallExpression, + FunctionDeclaration, + FunctionExpression, + ArrowFunctionExpression, + DirectiveLiteral, +} from '@babel/types'; import { ReanimatedPluginPass } from './types'; import { processWorklets } from './processWorklets'; import { processIfWorkletNode } from './processIfWorkletNode'; @@ -8,7 +14,7 @@ import { processIfGestureHandlerEventCallbackFunctionNode } from './processIfGes import { processInlineStylesWarning } from './processInlineStylesWarning'; import { injectVersion } from './injectVersion'; -export default function ({ types: t }: typeof BabelCore): BabelCore.PluginItem { +module.exports = function (): PluginItem { return { pre() { // allows adding custom globals such as host-functions @@ -20,36 +26,31 @@ export default function ({ types: t }: typeof BabelCore): BabelCore.PluginItem { }, visitor: { DirectiveLiteral: { - enter(path: BabelCore.NodePath) { + enter(path: NodePath) { injectVersion(path); }, }, CallExpression: { - enter( - path: BabelCore.NodePath, - state: ReanimatedPluginPass - ) { - processWorklets(t, path, state); + enter(path: NodePath, state: ReanimatedPluginPass) { + processWorklets(path, state); }, }, 'FunctionDeclaration|FunctionExpression|ArrowFunctionExpression': { enter( - path: BabelCore.NodePath< - | BabelTypes.FunctionDeclaration - | BabelTypes.FunctionExpression - | BabelTypes.ArrowFunctionExpression + path: NodePath< + FunctionDeclaration | FunctionExpression | ArrowFunctionExpression >, state: ReanimatedPluginPass ) { - processIfWorkletNode(t, path, state); - processIfGestureHandlerEventCallbackFunctionNode(t, path, state); + processIfWorkletNode(path, state); + processIfGestureHandlerEventCallbackFunctionNode(path, state); }, }, JSXAttribute: { enter(path, state) { - processInlineStylesWarning(t, path, state); + processInlineStylesWarning(path, state); }, }, }, }; -} +}; diff --git a/plugin/src/processIfGestureHandlerEventCallbackFunctionNode.ts b/plugin/src/processIfGestureHandlerEventCallbackFunctionNode.ts index ad271260b60..ca2c0f28ec6 100644 --- a/plugin/src/processIfGestureHandlerEventCallbackFunctionNode.ts +++ b/plugin/src/processIfGestureHandlerEventCallbackFunctionNode.ts @@ -1,5 +1,14 @@ -import * as BabelCore from '@babel/core'; -import * as BabelTypes from '@babel/types'; +import { NodePath } from '@babel/core'; +import { + FunctionDeclaration, + FunctionExpression, + ArrowFunctionExpression, + isIdentifier, + isCallExpression, + Expression, + isMemberExpression, + isExpression, +} from '@babel/types'; import { ReanimatedPluginPass } from './types'; import { processWorkletFunction } from './processWorkletFunction'; @@ -33,11 +42,8 @@ const gestureHandlerBuilderMethods = new Set([ ]); export function processIfGestureHandlerEventCallbackFunctionNode( - t: typeof BabelCore.types, - fun: BabelCore.NodePath< - | BabelTypes.FunctionDeclaration - | BabelTypes.FunctionExpression - | BabelTypes.ArrowFunctionExpression + fun: NodePath< + FunctionDeclaration | FunctionExpression | ArrowFunctionExpression >, state: ReanimatedPluginPass ) { @@ -90,45 +96,39 @@ export function processIfGestureHandlerEventCallbackFunctionNode( */ if ( - t.isCallExpression(fun.parent) && - t.isExpression(fun.parent.callee) && - isGestureObjectEventCallbackMethod(t, fun.parent.callee) + isCallExpression(fun.parent) && + isExpression(fun.parent.callee) && + isGestureObjectEventCallbackMethod(fun.parent.callee) ) { - processWorkletFunction(t, fun, state); + processWorkletFunction(fun, state); } } -function isGestureObjectEventCallbackMethod( - t: typeof BabelCore.types, - node: BabelTypes.Expression -) { +function isGestureObjectEventCallbackMethod(node: Expression) { // Checks if node matches the pattern `Gesture.Foo()[*].onBar` // where `[*]` represents any number of method calls. return ( - t.isMemberExpression(node) && - t.isIdentifier(node.property) && + isMemberExpression(node) && + isIdentifier(node.property) && gestureHandlerBuilderMethods.has(node.property.name) && - containsGestureObject(t, node.object) + containsGestureObject(node.object) ); } -function containsGestureObject( - t: typeof BabelCore.types, - node: BabelTypes.Expression -) { +function containsGestureObject(node: Expression) { // Checks if node matches the pattern `Gesture.Foo()[*]` // where `[*]` represents any number of chained method calls, like `.something(42)`. // direct call - if (isGestureObject(t, node)) { + if (isGestureObject(node)) { return true; } // method chaining if ( - t.isCallExpression(node) && - t.isMemberExpression(node.callee) && - containsGestureObject(t, node.callee.object) + isCallExpression(node) && + isMemberExpression(node.callee) && + containsGestureObject(node.callee.object) ) { return true; } @@ -136,10 +136,7 @@ function containsGestureObject( return false; } -function isGestureObject( - t: typeof BabelCore.types, - node: BabelTypes.Expression -) { +function isGestureObject(node: Expression) { // Checks if node matches `Gesture.Tap()` or similar. /* node: CallExpression( @@ -150,11 +147,11 @@ function isGestureObject( ) */ return ( - t.isCallExpression(node) && - t.isMemberExpression(node.callee) && - t.isIdentifier(node.callee.object) && + isCallExpression(node) && + isMemberExpression(node.callee) && + isIdentifier(node.callee.object) && node.callee.object.name === 'Gesture' && - t.isIdentifier(node.callee.property) && + isIdentifier(node.callee.property) && gestureHandlerGestureObjects.has(node.callee.property.name) ); } diff --git a/plugin/src/processIfWorkletNode.ts b/plugin/src/processIfWorkletNode.ts index 5da736b86b2..36bfb962a36 100644 --- a/plugin/src/processIfWorkletNode.ts +++ b/plugin/src/processIfWorkletNode.ts @@ -1,14 +1,17 @@ -import * as BabelCore from '@babel/core'; -import * as BabelTypes from '@babel/types'; +import { NodePath } from '@babel/core'; +import { + FunctionDeclaration, + FunctionExpression, + ArrowFunctionExpression, + isBlockStatement, + isDirectiveLiteral, +} from '@babel/types'; import { ReanimatedPluginPass } from './types'; import { processWorkletFunction } from './processWorkletFunction'; export function processIfWorkletNode( - t: typeof BabelCore.types, - fun: BabelCore.NodePath< - | BabelTypes.FunctionDeclaration - | BabelTypes.FunctionExpression - | BabelTypes.ArrowFunctionExpression + fun: NodePath< + FunctionDeclaration | FunctionExpression | ArrowFunctionExpression >, state: ReanimatedPluginPass ) { @@ -18,7 +21,7 @@ export function processIfWorkletNode( if ( value === 'worklet' && path.getFunctionParent() === fun && - BabelTypes.isBlockStatement(fun.node.body) + isBlockStatement(fun.node.body) ) { // make sure "worklet" is listed among directives for the fun // this is necessary as because of some bug, babel will attempt to @@ -29,11 +32,11 @@ export function processIfWorkletNode( directives.length > 0 && directives.some( (directive) => - t.isDirectiveLiteral(directive.value) && + isDirectiveLiteral(directive.value) && directive.value.value === 'worklet' ) ) { - processWorkletFunction(t, fun, state); + processWorkletFunction(fun, state); } } }, diff --git a/plugin/src/processInlineStylesWarning.ts b/plugin/src/processInlineStylesWarning.ts index 4aaf87bb65e..7ac53d1a5a7 100644 --- a/plugin/src/processInlineStylesWarning.ts +++ b/plugin/src/processInlineStylesWarning.ts @@ -1,34 +1,52 @@ -import * as BabelCore from '@babel/core'; -import * as BabelTypes from '@babel/types'; +import { NodePath } from '@babel/core'; +import { + MemberExpression, + callExpression, + arrowFunctionExpression, + isMemberExpression, + isArrayExpression, + isObjectExpression, + ArrayExpression, + ObjectExpression, + isObjectProperty, + JSXAttribute, + isJSXExpressionContainer, + Expression, + identifier, + stringLiteral, + expressionStatement, + memberExpression, + returnStatement, + blockStatement, + ObjectProperty, + isIdentifier, +} from '@babel/types'; import { isRelease } from './utils'; import { ReanimatedPluginPass } from './types'; -function generateInlineStylesWarning( - t: typeof BabelCore.types, - memberExpression: BabelCore.NodePath -) { +function generateInlineStylesWarning(path: NodePath) { // replaces `sharedvalue.value` with `(()=>{console.warn(require('react-native-reanimated').getUseOfValueInStyleWarning());return sharedvalue.value;})()` - return t.callExpression( - t.arrowFunctionExpression( + return callExpression( + arrowFunctionExpression( [], - t.blockStatement([ - t.expressionStatement( - t.callExpression( - t.memberExpression(t.identifier('console'), t.identifier('warn')), + blockStatement([ + expressionStatement( + callExpression( + memberExpression(identifier('console'), identifier('warn')), [ - t.callExpression( - t.memberExpression( - t.callExpression(t.identifier('require'), [ - t.stringLiteral('react-native-reanimated'), + callExpression( + memberExpression( + callExpression(identifier('require'), [ + stringLiteral('react-native-reanimated'), ]), - t.identifier('getUseOfValueInStyleWarning') + identifier('getUseOfValueInStyleWarning') ), [] ), ] ) ), - t.returnStatement(memberExpression.node), + returnStatement(path.node), ]) ), [] @@ -36,35 +54,29 @@ function generateInlineStylesWarning( } function processPropertyValueForInlineStylesWarning( - t: typeof BabelCore.types, - path: BabelCore.NodePath + path: NodePath ) { // if it's something like object.value then raise a warning - if (t.isMemberExpression(path.node) && t.isIdentifier(path.node.property)) { + if (isMemberExpression(path.node) && isIdentifier(path.node.property)) { if (path.node.property.name === 'value') { path.replaceWith( - generateInlineStylesWarning( - t, - path as BabelCore.NodePath - ) + generateInlineStylesWarning(path as NodePath) ); } } } function processTransformPropertyForInlineStylesWarning( - t: typeof BabelCore.types, - path: BabelCore.NodePath + path: NodePath ) { - if (t.isArrayExpression(path.node)) { + if (isArrayExpression(path.node)) { const elements = path.get('elements') as Array< - BabelCore.NodePath + NodePath >; for (const element of elements) { - if (t.isObjectExpression(element.node)) { + if (isObjectExpression(element.node)) { processStyleObjectForInlineStylesWarning( - t, - element as BabelCore.NodePath + element as NodePath ); // why is it not inferred? [TO DO] } } @@ -72,62 +84,56 @@ function processTransformPropertyForInlineStylesWarning( } function processStyleObjectForInlineStylesWarning( - t: typeof BabelCore.types, - path: BabelCore.NodePath + path: NodePath ) { const properties = path.get('properties') as Array< - BabelCore.NodePath + NodePath >; for (const property of properties) { - if (!BabelTypes.isObjectProperty(property.node)) continue; - const value = property.get('value') as BabelCore.NodePath< - BabelTypes.ObjectProperty['value'] - >; - if (t.isObjectProperty(property)) { + if (!isObjectProperty(property.node)) continue; + const value = property.get('value') as NodePath; + if (isObjectProperty(property)) { if ( - t.isIdentifier(property.node.key) && + isIdentifier(property.node.key) && property.node.key.name === 'transform' ) { - processTransformPropertyForInlineStylesWarning(t, value); + processTransformPropertyForInlineStylesWarning(value); } else { - processPropertyValueForInlineStylesWarning(t, value); + processPropertyValueForInlineStylesWarning(value); } } } } export function processInlineStylesWarning( - t: typeof BabelCore.types, - path: BabelCore.NodePath, + path: NodePath, state: ReanimatedPluginPass ) { if (isRelease()) return; if (state.opts.disableInlineStylesWarning) return; if (path.node.name.name !== 'style') return; - if (!t.isJSXExpressionContainer(path.node.value)) return; + if (!isJSXExpressionContainer(path.node.value)) return; const expression = path .get('value') - .get('expression') as BabelCore.NodePath; + .get('expression') as NodePath; // style={[{...}, {...}]} - if (BabelTypes.isArrayExpression(expression.node)) { + if (isArrayExpression(expression.node)) { const elements = expression.get('elements') as Array< - BabelCore.NodePath + NodePath >; for (const element of elements) { - if (t.isObjectExpression(element.node)) { + if (isObjectExpression(element.node)) { processStyleObjectForInlineStylesWarning( - t, - element as BabelCore.NodePath + element as NodePath ); // why is it not inferred? [TO DO] } } } // style={{...}} - else if (t.isObjectExpression(expression.node)) { + else if (isObjectExpression(expression.node)) { processStyleObjectForInlineStylesWarning( - t, - expression as BabelCore.NodePath + expression as NodePath ); // why is it not inferred? [TO DO] } } diff --git a/plugin/src/processWorkletFunction.ts b/plugin/src/processWorkletFunction.ts index e640226f0f8..f3df7ef19e1 100644 --- a/plugin/src/processWorkletFunction.ts +++ b/plugin/src/processWorkletFunction.ts @@ -1,27 +1,35 @@ -import * as BabelCore from '@babel/core'; -import * as BabelTypes from '@babel/types'; +import { NodePath } from '@babel/core'; +import { + FunctionDeclaration, + FunctionExpression, + ArrowFunctionExpression, + callExpression, + isScopable, + isExportNamedDeclaration, + isArrowFunctionExpression, + variableDeclaration, + isFunctionParent, + variableDeclarator, +} from '@babel/types'; import { ReanimatedPluginPass } from './types'; import { makeWorklet } from './makeWorklet'; export function processWorkletFunction( - t: typeof BabelCore.types, - fun: BabelCore.NodePath< - | BabelTypes.FunctionDeclaration - | BabelTypes.FunctionExpression - | BabelTypes.ArrowFunctionExpression + fun: NodePath< + FunctionDeclaration | FunctionExpression | ArrowFunctionExpression >, state: ReanimatedPluginPass ) { // Replaces FunctionDeclaration, FunctionExpression or ArrowFunctionExpression // with a workletized version of itself. - if (!t.isFunctionParent(fun)) { + if (!isFunctionParent(fun)) { return; } - const newFun = makeWorklet(t, fun, state); + const newFun = makeWorklet(fun, state); - const replacement = t.callExpression(newFun, []); + const replacement = callExpression(newFun, []); // we check if function needs to be assigned to variable declaration. // This is needed if function definition directly in a scope. Some other ways @@ -29,13 +37,11 @@ export function processWorkletFunction( // const ggg = function foo() { } // ^ in such a case we don't need to define variable for the function const needDeclaration = - t.isScopable(fun.parent) || t.isExportNamedDeclaration(fun.parent); + isScopable(fun.parent) || isExportNamedDeclaration(fun.parent); fun.replaceWith( - !BabelTypes.isArrowFunctionExpression(fun.node) && - fun.node.id && - needDeclaration - ? t.variableDeclaration('const', [ - t.variableDeclarator(fun.node.id, replacement), + !isArrowFunctionExpression(fun.node) && fun.node.id && needDeclaration + ? variableDeclaration('const', [ + variableDeclarator(fun.node.id, replacement), ]) : replacement ); diff --git a/plugin/src/processWorkletObjectMethod.ts b/plugin/src/processWorkletObjectMethod.ts index 1fb5a1d0e12..68f6ba18657 100644 --- a/plugin/src/processWorkletObjectMethod.ts +++ b/plugin/src/processWorkletObjectMethod.ts @@ -1,24 +1,28 @@ -import * as BabelCore from '@babel/core'; -import * as BabelTypes from '@babel/types'; +import { NodePath } from '@babel/core'; +import { + ObjectMethod, + identifier, + isIdentifier, + isFunctionParent, + objectProperty, + callExpression, +} from '@babel/types'; import { ReanimatedPluginPass } from './types'; import { makeWorklet } from './makeWorklet'; export function processWorkletObjectMethod( - t: typeof BabelCore.types, - path: BabelCore.NodePath, + path: NodePath, state: ReanimatedPluginPass ) { // Replaces ObjectMethod with a workletized version of itself. - if (!BabelTypes.isFunctionParent(path)) return; + if (!isFunctionParent(path)) return; - const newFun = makeWorklet(t, path, state); + const newFun = makeWorklet(path, state); - const replacement = BabelTypes.objectProperty( - BabelTypes.identifier( - BabelTypes.isIdentifier(path.node.key) ? path.node.key.name : '' - ), - t.callExpression(newFun, []) + const replacement = objectProperty( + identifier(isIdentifier(path.node.key) ? path.node.key.name : ''), + callExpression(newFun, []) ); path.replaceWith(replacement); diff --git a/plugin/src/processWorklets.ts b/plugin/src/processWorklets.ts index 2a31482d06c..e6e02536972 100644 --- a/plugin/src/processWorklets.ts +++ b/plugin/src/processWorklets.ts @@ -1,12 +1,19 @@ -import * as BabelCore from '@babel/core'; -import * as BabelTypes from '@babel/types'; +import { NodePath } from '@babel/core'; +import { + CallExpression, + isSequenceExpression, + isObjectExpression, + ObjectMethod, + ObjectProperty, + isObjectMethod, + FunctionDeclaration, + FunctionExpression, + ArrowFunctionExpression, +} from '@babel/types'; import { ReanimatedPluginPass } from './types'; import { processWorkletObjectMethod } from './processWorkletObjectMethod'; import { processWorkletFunction } from './processWorkletFunction'; -/** - * holds a map of function names as keys and array of argument indexes as values which should be automatically workletized(they have to be functions)(starting from 0) - */ const functionArgsToWorkletize = new Map([ ['useFrameCallback', [0]], ['useAnimatedStyle', [0]], @@ -29,11 +36,10 @@ const objectHooks = new Set([ ]); export function processWorklets( - t: typeof BabelCore.types, - path: BabelCore.NodePath, + path: NodePath, state: ReanimatedPluginPass ) { - const callee = BabelTypes.isSequenceExpression(path.node.callee) + const callee = isSequenceExpression(path.node.callee) ? path.node.callee.expressions[path.node.callee.expressions.length - 1] : path.node.callee; @@ -45,34 +51,24 @@ export function processWorklets( if ( objectHooks.has(name) && - BabelTypes.isObjectExpression( - ( - path.get('arguments.0') as BabelCore.NodePath< - BabelTypes.CallExpression['arguments'][number] - > - ).node + isObjectExpression( + (path.get('arguments.0') as NodePath) + .node ) ) { const properties = path.get('arguments.0.properties') as Array< - BabelCore.NodePath + NodePath >; for (const property of properties) { - if (t.isObjectMethod(property.node)) { - processWorkletObjectMethod( - t, - property as BabelCore.NodePath, - state - ); + if (isObjectMethod(property.node)) { + processWorkletObjectMethod(property as NodePath, state); } else { - const value = property.get('value') as BabelCore.NodePath< - BabelTypes.ObjectProperty['value'] + const value = property.get('value') as NodePath< + ObjectProperty['value'] >; processWorkletFunction( - t, - value as BabelCore.NodePath< - | BabelTypes.FunctionDeclaration - | BabelTypes.FunctionExpression - | BabelTypes.ArrowFunctionExpression + value as NodePath< + FunctionDeclaration | FunctionExpression | ArrowFunctionExpression >, state ); // temporarily given 3 types [TO DO] @@ -83,11 +79,8 @@ export function processWorklets( if (Array.isArray(indexes)) { indexes.forEach((index) => { processWorkletFunction( - t, - path.get(`arguments.${index}`) as BabelCore.NodePath< - | BabelTypes.FunctionDeclaration - | BabelTypes.FunctionExpression - | BabelTypes.ArrowFunctionExpression + path.get(`arguments.${index}`) as NodePath< + FunctionDeclaration | FunctionExpression | ArrowFunctionExpression >, state ); // temporarily given 3 types [TO DO] diff --git a/plugin/src/types.ts b/plugin/src/types.ts index 61ff03fc879..ba7c7018221 100644 --- a/plugin/src/types.ts +++ b/plugin/src/types.ts @@ -1,7 +1,7 @@ -import * as BabelCore from '@babel/core'; +import { BabelFile } from '@babel/core'; export interface ReanimatedPluginPass { - file: BabelCore.BabelFile; + file: BabelFile; key: string; opts: { relativeSourceLocation?: boolean;