{"_id":"babel-jsx-utils","_rev":"3473422","name":"babel-jsx-utils","description":"Utilities for working with Babel and JSX","dist-tags":{"latest":"1.1.0"},"maintainers":[{"name":"ascorbic","email":"m@mk.gg"}],"time":{"modified":"2024-08-27T19:43:02.000Z","created":"2020-09-18T10:28:52.199Z","1.1.0":"2021-03-16T10:15:20.355Z","1.0.1":"2020-09-18T11:12:06.861Z","1.0.0":"2020-09-18T10:28:52.199Z"},"users":{},"author":{"name":"Matt Kane","email":"m@mk.gg"},"versions":{"1.1.0":{"name":"babel-jsx-utils","version":"1.1.0","description":"Utilities for working with Babel and JSX","main":"dist/index.js","license":"MIT","author":{"name":"Matt Kane","email":"m@mk.gg"},"devDependencies":{"@babel/core":"^7.11.6","@babel/preset-env":"^7.11.5","@babel/preset-react":"^7.10.4","@babel/preset-typescript":"^7.10.4","@babel/traverse":"^7.11.5","@types/babel__core":"^7.1.9","@types/babel__traverse":"^7.0.14","@types/jest":"^26.0.14","@types/node":"^14.11.1","@typescript-eslint/eslint-plugin":"^4.1.1","@typescript-eslint/parser":"^4.1.1","babel-jest":"^26.3.0","eslint":"^7.9.0","eslint-config-prettier":"^6.11.0","jest":"^26.4.2","microbundle":"^0.12.3","prettier":"^2.1.2","typescript":"^4.0.2"},"scripts":{"start":"microbundle watch --target node","build":"microbundle build --target node","prepublishOnly":"yarn build","test":"jest","lint":"eslint src"},"_id":"babel-jsx-utils@1.1.0","dist":{"shasum":"304ce4fce0c86cbeee849551a45eb4ed1036381a","size":5033,"noattachment":false,"key":"/babel-jsx-utils/-/babel-jsx-utils-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-jsx-utils/download/babel-jsx-utils-1.1.0.tgz"},"_npmUser":{"name":"ascorbic","email":"m@mk.gg"},"directories":{},"maintainers":[{"name":"ascorbic","email":"m@mk.gg"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-jsx-utils_1.1.0_1615889720218_0.592795546023857"},"_hasShrinkwrap":false,"publish_time":1615889720355,"_cnpm_publish_time":1615889720355,"_cnpmcore_publish_time":"2021-12-16T20:19:02.332Z"},"1.0.1":{"name":"babel-jsx-utils","version":"1.0.1","description":"Utilities for working with Babel and JSX","main":"dist/index.js","license":"MIT","author":{"name":"Matt Kane","email":"m@mk.gg"},"devDependencies":{"@babel/core":"^7.11.6","@babel/preset-env":"^7.11.5","@babel/preset-react":"^7.10.4","@babel/preset-typescript":"^7.10.4","@babel/traverse":"^7.11.5","@types/babel__core":"^7.1.9","@types/babel__traverse":"^7.0.14","@types/jest":"^26.0.14","@types/node":"^14.11.1","@typescript-eslint/eslint-plugin":"^4.1.1","@typescript-eslint/parser":"^4.1.1","babel-jest":"^26.3.0","eslint":"^7.9.0","eslint-config-prettier":"^6.11.0","jest":"^26.4.2","microbundle":"^0.12.3","prettier":"^2.1.2","typescript":"^4.0.2"},"scripts":{"start":"microbundle watch --target node","build":"microbundle build --target node","prepublishOnly":"yarn build","test":"jest","lint":"eslint src"},"_id":"babel-jsx-utils@1.0.1","dist":{"shasum":"f2d171cba526594e7d69e9893d634502cf950f07","size":4952,"noattachment":false,"key":"/babel-jsx-utils/-/babel-jsx-utils-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-jsx-utils/download/babel-jsx-utils-1.0.1.tgz"},"maintainers":[{"name":"ascorbic","email":"m@mk.gg"}],"_npmUser":{"name":"ascorbic","email":"m@mk.gg"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-jsx-utils_1.0.1_1600427526759_0.002603186786435341"},"_hasShrinkwrap":false,"publish_time":1600427526861,"_cnpm_publish_time":1600427526861,"_cnpmcore_publish_time":"2021-12-16T20:19:02.530Z"},"1.0.0":{"name":"babel-jsx-utils","version":"1.0.0","description":"Utilities for working with Babel and JSX","main":"dist/index.js","license":"MIT","author":{"name":"Matt Kane","email":"m@mk.gg"},"devDependencies":{"@babel/core":"^7.11.6","@babel/preset-env":"^7.11.5","@babel/preset-react":"^7.10.4","@babel/preset-typescript":"^7.10.4","@babel/traverse":"^7.11.5","@types/babel__core":"^7.1.9","@types/babel__traverse":"^7.0.14","@types/jest":"^26.0.14","@types/node":"^14.11.1","@typescript-eslint/eslint-plugin":"^4.1.1","@typescript-eslint/parser":"^4.1.1","babel-jest":"^26.3.0","eslint":"^7.9.0","eslint-config-prettier":"^6.11.0","jest":"^26.4.2","microbundle":"^0.12.3","prettier":"^2.1.2","typescript":"^4.0.2"},"scripts":{"start":"microbundle watch --target node","build":"microbundle build --target node","test":"jest","lint":"eslint src"},"_id":"babel-jsx-utils@1.0.0","dist":{"shasum":"46c86fb1013b4820df424ead41b3c73198318c38","size":7837,"noattachment":false,"key":"/babel-jsx-utils/-/babel-jsx-utils-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-jsx-utils/download/babel-jsx-utils-1.0.0.tgz"},"maintainers":[{"name":"ascorbic","email":"m@mk.gg"}],"_npmUser":{"name":"ascorbic","email":"m@mk.gg"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-jsx-utils_1.0.0_1600424932056_0.11228645536435056"},"_hasShrinkwrap":false,"publish_time":1600424932199,"_cnpm_publish_time":1600424932199,"_cnpmcore_publish_time":"2021-12-16T20:19:02.756Z"}},"readme":"# babel-jsx-utils\n\nThis library allows you to resolve the actual values of attributes when parsing JSX with Babel. This is useful for things like Babel plugins. It evaluates the value in the local scope, so local variables are ok, but properties passed to the component are not.\n\nFor example:\n\n```jsx\n// OK\nexport function Logo() {\n    const src = \"trex.png\";\n\n    return <img src={src} alt=\"T-Rex\" />;\n}\n```\n\n```jsx\n// Not OK\nexport function Logo({ src }) {\n    return <img src={src} alt=\"T-Rex\" />;\n}\n```\n\nIt can handle expressions, but not function calls:\n\n```jsx\n// OK\nexport function Logo() {\n    const width = 100 * 2;\n\n    return <img src={\"trex.png\"} width={width} alt=\"T-Rex\" />;\n}\n```\n\n```jsx\n// Not OK\nexport function Logo() {\n    function double(value) {\n        return value * 2;\n    }\n\n    const width = double(100);\n\n    return <img src={\"trex.png\"} width={width} alt=\"T-Rex\" />;\n}\n```\n\n## Installation\n\nInstall:\n\n```shell\nyarn install babel-jsx-utils\n```\nor\n\n```shell\nnpm install babel-jsx-utils\n```\n\n## Usage\n\n```js\nimport { parse, traverse } from \"@babel/core\";\n\nconst ast = parse(`<Foo bar=\"hello\" />`, {\n    filename: \"foo.js\",\n    presets: [\"@babel/preset-react\"],\n});\n\ntraverse(ast, {\n    JSXOpeningElement(nodePath) {\n        const values = getAttributeValues(nodePath);\n        // values = { bar: \"Hello\" }\n    },\n});\n```\n\nFor more examples, see the tests\n\n## API\n\n```typescript\n/**\n * Get all attribute values of a JSX element. This only includes values that can be\n * statically-analysed. Pass the `onError` callback to be notified if an attribute cannot be resolved.\n *\n * @param nodePath The NodePath of the JSX opening element\n * @param onError Called with the attribute name if it is present but cannot be resolved\n * @param include If present, only these props are evaluated. Does not apply to spread attributes.\n */\nexport declare function getAttributeValues(\n    nodePath:\n        | CoreNodePath<JSXOpeningElement>\n        | TraverseNodePath<JSXOpeningElement>,\n    onError?: (attributeName: string) => void,\n    include?: Set<string>\n): Record<string, any>;\n/**\n * Attempt to get the value of a JSX attribute. Returns an object with the\n * properties `confident`, which is false if the value cannot be resolved\n * in the current scope, and `value` which is the value if it can be.\n *\n * If the attribute is empty, then the returned value is `true`, e.g.\n * `<Image eager />` would return `true` for the `eager` attribute.\n *\n * @param nodePath The NodePath of the JSXAttribute\n */\nexport declare function getAttributeValue<T = unknown>(\n    nodePath: CoreNodePath<JSXAttribute> | TraverseNodePath<JSXAttribute>\n): {\n    confident: boolean;\n    value: T | true;\n};\n```\n","_attachments":{},"license":"MIT"}