Innovenergy_trunk/frontend/node_modules/@babel/plugin-transform-parameters/lib/shadow-utils.js.map

1 line
4.9 KiB
Plaintext
Raw Normal View History

{"version":3,"names":["iifeVisitor","path","state","scope","node","name","getBinding","parent","hasOwnBinding","needsOuterBinding","stop","skip","collectShadowedParamsNames","param","functionScope","shadowedParams","Object","keys","getBindingIdentifiers","constantViolations","bindings","redeclarator","type","init","declaration","parentPath","isFor","get","remove","add","buildScopeIIFE","body","args","params","push","t","identifier","returnStatement","callExpression","arrowFunctionExpression"],"sources":["../src/shadow-utils.ts"],"sourcesContent":["import { types as t } from \"@babel/core\";\nimport type { NodePath, Scope, Visitor } from \"@babel/traverse\";\n\ntype State = {\n needsOuterBinding: boolean;\n scope: Scope;\n};\n\nexport const iifeVisitor: Visitor<State> = {\n \"ReferencedIdentifier|BindingIdentifier\"(\n path: NodePath<t.Identifier>,\n state,\n ) {\n const { scope, node } = path;\n const { name } = node;\n\n if (\n name === \"eval\" ||\n (scope.getBinding(name) === state.scope.parent.getBinding(name) &&\n state.scope.hasOwnBinding(name))\n ) {\n state.needsOuterBinding = true;\n path.stop();\n }\n },\n // type annotations don't use or introduce \"real\" bindings\n \"TypeAnnotation|TSTypeAnnotation|TypeParameterDeclaration|TSTypeParameterDeclaration\":\n (path: NodePath) => path.skip(),\n};\n\nexport function collectShadowedParamsNames(\n param: NodePath<t.Function[\"params\"][number]>,\n functionScope: Scope,\n shadowedParams: Set<string>,\n) {\n for (const name of Object.keys(param.getBindingIdentifiers())) {\n const constantViolations = functionScope.bindings[name]?.constantViolations;\n if (constantViolations) {\n for (const redeclarator of constantViolations) {\n const node = redeclarator.node;\n // If a constant violation is a var or a function declaration,\n // we first check to see if it's a var without an init.\n // If so, we remove that declarator.\n // Otherwise, we have to wrap it in an IIFE.\n switch (node.type) {\n case \"VariableDeclarator\": {\n if (node.init === null) {\n const declaration = redeclarator.parentPath;\n // The following uninitialized var declarators should not be removed\n // for (var x in {})\n // for (var x;;)\n if (\n !declaration.parentPath.isFor() ||\n declaration.parentPath.get(\"body\") === declaration\n ) {\n redeclarator.remove();\n break;\n }\n }\n\n shadowedParams.add(name);\n break;\n }\n case \"FunctionDeclaration\":\n shadowedParams.add(name);\n break;\n }\n }\n }\n }\n}\n\nexport function buildScopeIIFE(\n shadowedParams: Set<string>,\n body: t.BlockStatement,\n) {\n const args = [];\n const params = [];\n\n for (const name of shadowedParams) {\n // We create them twice; the other option is to use t.cloneNode\n args.push(t.identifier(name));\n params.push(t.identifier(name));\n }\n\n return t.returnStatement(\n t.callExpression(t.arrowFunctionExpression(params, body), args),\n );\n}\n"],"mappings":";;;;;;;;AAAA;AAQO,MAAMA,WAA2B,GAAG;EACzC,wCAAwC,CACtCC,IAA4B,EAC5BC,KAAK,EACL;IACA,MAAM;MAAEC,KAAK;MAAEC;IAAK,CAAC,GAAGH,IAAI;IAC5B,MAAM;MAAEI;IAAK,CAAC,GAAGD,IAAI;IAErB,IACEC,IAAI,KAAK,MAAM,IACdF,KAAK,CAACG,UAAU,CAACD,IAAI,CAAC,KAAKH,KAAK,CAACC,KAAK,CAACI,MAAM,CAACD,UAAU,CAACD,IAAI,CAAC,IAC7DH,KAAK,CAACC,KAAK,CAACK,aAAa,CAACH,IAAI,CAAE,EAClC;MACAH,KAAK,CAACO,iBAAiB,GAAG,IAAI;MAC9BR,IAAI,CAACS,IAAI,EAAE;IACb;EACF,CAAC;EAED,qFAAqF,EAClFT,IAAc,IAAKA,IAAI,CAACU,IAAI;AACjC,CAAC;AAAC;AAEK,SAASC,0BAA0B,CACxCC,KAA6C,EAC7CC,aAAoB,EACpBC,cAA2B,EAC3B;EACA,KAAK,MAAMV,IAAI,IAAIW,MAAM,CAACC,IAAI,CAACJ,KAAK,CAACK,qBAAqB,EAAE,CAAC,EAAE;IAAA;IAC7D,MAAMC,kBAAkB,4BAAGL,aAAa,CAACM,QAAQ,CAACf,IAAI,CAAC,qBAA5B,sBAA8Bc,kBAAkB;IAC3E,IAAIA,kBAAkB,EAAE;MACtB,KAAK,MAAME,YAAY,IAAIF,kBAAkB,EAAE;QAC7C,MAAMf,