Skip to content

Commit

Permalink
Merge pull request #1133 from joeycozza/master
Browse files Browse the repository at this point in the history
providing filename when running babel.parse in icu.macro
  • Loading branch information
jamuhl authored Jun 12, 2020
2 parents 825ff82 + 75aa722 commit dae4eba
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion icu.macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function ICUMacro({ references, state, babel }) {
children: referencePath.parentPath.parentPath.get('children'),
},
babel,
state,
);
} else {
// throw a helpful error message or something :)
Expand Down Expand Up @@ -174,7 +175,7 @@ function selectAsJSX(parentPath, { attributes }, babel) {
parentPath.replaceWith(buildTransElement(extracted, extracted.attributesToCopy, t, true));
}

function transAsJSX(parentPath, { attributes, children }, babel) {
function transAsJSX(parentPath, { attributes, children }, babel, { filename }) {
const defaultsAttr = findAttribute('defaults', attributes);
const componentsAttr = findAttribute('components', attributes);
// if there is "defaults" attribute and no "components" attribute, parse defaults and extract from the parsed defaults instead of children
Expand All @@ -186,6 +187,7 @@ function transAsJSX(parentPath, { attributes, children }, babel) {
const defaultsExpression = defaultsAttr.node.value.value;
const parsed = babel.parse(`<>${defaultsExpression}</>`, {
presets: ['@babel/react'],
filename,
}).program.body[0].expression.children;

extracted = processTrans(parsed, babel);
Expand Down

0 comments on commit dae4eba

Please sign in to comment.