source: imaps-frontend/node_modules/@babel/plugin-transform-react-jsx-source/lib/index.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[d565449]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _helperPluginUtils = require("@babel/helper-plugin-utils");
8var _core = require("@babel/core");
9const TRACE_ID = "__source";
10const FILE_NAME_VAR = "_jsxFileName";
11const createNodeFromNullish = (val, fn) => val == null ? _core.types.nullLiteral() : fn(val);
12var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
13 api.assertVersion(7);
14 function makeTrace(fileNameIdentifier, {
15 line,
16 column
17 }) {
18 const fileLineLiteral = createNodeFromNullish(line, _core.types.numericLiteral);
19 const fileColumnLiteral = createNodeFromNullish(column, c => _core.types.numericLiteral(c + 1));
20 return _core.template.expression.ast`{
21 fileName: ${fileNameIdentifier},
22 lineNumber: ${fileLineLiteral},
23 columnNumber: ${fileColumnLiteral},
24 }`;
25 }
26 const isSourceAttr = attr => _core.types.isJSXAttribute(attr) && attr.name.name === TRACE_ID;
27 return {
28 name: "transform-react-jsx-source",
29 visitor: {
30 JSXOpeningElement(path, state) {
31 const {
32 node
33 } = path;
34 if (!node.loc || path.node.attributes.some(isSourceAttr)) {
35 return;
36 }
37 if (!state.fileNameIdentifier) {
38 const fileNameId = path.scope.generateUidIdentifier(FILE_NAME_VAR);
39 state.fileNameIdentifier = fileNameId;
40 path.scope.getProgramParent().push({
41 id: fileNameId,
42 init: _core.types.stringLiteral(state.filename || "")
43 });
44 }
45 node.attributes.push(_core.types.jsxAttribute(_core.types.jsxIdentifier(TRACE_ID), _core.types.jsxExpressionContainer(makeTrace(_core.types.cloneNode(state.fileNameIdentifier), node.loc.start))));
46 }
47 }
48 };
49});
50
51//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.