Skip to content

Commit

Permalink
Fix jsxDEV for generated elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Aug 28, 2020
1 parent e498bee commit 929f3ce
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/babel-helper-builder-react-jsx-experimental/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ export function helper(babel, options) {
}
}

const source = t.jsxAttribute(
t.jsxIdentifier("__source"),
t.jsxExpressionContainer(makeSource(path, state)),
);
const hasSource = Boolean(path.node.loc);

const source = hasSource
? t.jsxAttribute(
t.jsxIdentifier("__source"),
t.jsxExpressionContainer(makeSource(path, state)),
)
: // the element was generated and doesn't have location information
null;
const self = t.jsxAttribute(
t.jsxIdentifier("__self"),
t.jsxExpressionContainer(t.thisExpression()),
);

path.pushContainer("attributes", [source, self]);
path.pushContainer("attributes", hasSource ? [source, self] : self);
},
};

Expand Down Expand Up @@ -434,12 +439,6 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
}

function makeSource(path, state) {
const location = path.node.loc;
if (!location) {
// the element was generated and doesn't have location information
return;
}

if (!state.fileNameIdentifier) {
const { filename = "" } = state;

Expand Down

0 comments on commit 929f3ce

Please sign in to comment.