diff options
| author | Christian Cleberg <[email protected]> | 2026-04-18 22:32:53 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-18 22:32:53 -0500 |
| commit | 580e798e16346eb894eb899edac82d2efdf40adc (patch) | |
| tree | 6dec3b7db678f781138b40d34da37d21ac8fbe7d /node_modules/@babel/plugin-transform-react-jsx-source/lib/index.js | |
| download | brand-bench-580e798e16346eb894eb899edac82d2efdf40adc.tar.gz brand-bench-580e798e16346eb894eb899edac82d2efdf40adc.tar.bz2 brand-bench-580e798e16346eb894eb899edac82d2efdf40adc.zip | |
initial commit
Diffstat (limited to 'node_modules/@babel/plugin-transform-react-jsx-source/lib/index.js')
| -rw-r--r-- | node_modules/@babel/plugin-transform-react-jsx-source/lib/index.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/node_modules/@babel/plugin-transform-react-jsx-source/lib/index.js b/node_modules/@babel/plugin-transform-react-jsx-source/lib/index.js new file mode 100644 index 0000000..68526b4 --- /dev/null +++ b/node_modules/@babel/plugin-transform-react-jsx-source/lib/index.js @@ -0,0 +1,51 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _helperPluginUtils = require("@babel/helper-plugin-utils"); +var _core = require("@babel/core"); +const TRACE_ID = "__source"; +const FILE_NAME_VAR = "_jsxFileName"; +const createNodeFromNullish = (val, fn) => val == null ? _core.types.nullLiteral() : fn(val); +var _default = exports.default = (0, _helperPluginUtils.declare)(api => { + api.assertVersion(7); + function makeTrace(fileNameIdentifier, { + line, + column + }) { + const fileLineLiteral = createNodeFromNullish(line, _core.types.numericLiteral); + const fileColumnLiteral = createNodeFromNullish(column, c => _core.types.numericLiteral(c + 1)); + return _core.template.expression.ast`{ + fileName: ${fileNameIdentifier}, + lineNumber: ${fileLineLiteral}, + columnNumber: ${fileColumnLiteral}, + }`; + } + const isSourceAttr = attr => _core.types.isJSXAttribute(attr) && attr.name.name === TRACE_ID; + return { + name: "transform-react-jsx-source", + visitor: { + JSXOpeningElement(path, state) { + const { + node + } = path; + if (!node.loc || path.node.attributes.some(isSourceAttr)) { + return; + } + if (!state.fileNameIdentifier) { + const fileNameId = path.scope.generateUidIdentifier(FILE_NAME_VAR); + state.fileNameIdentifier = fileNameId; + path.scope.getProgramParent().push({ + id: fileNameId, + init: _core.types.stringLiteral(state.filename || "") + }); + } + node.attributes.push(_core.types.jsxAttribute(_core.types.jsxIdentifier(TRACE_ID), _core.types.jsxExpressionContainer(makeTrace(_core.types.cloneNode(state.fileNameIdentifier), node.loc.start)))); + } + } + }; +}); + +//# sourceMappingURL=index.js.map |
