Skip to content

Commit

Permalink
Merge pull request #58 from Evalon/fix-babel-loading
Browse files Browse the repository at this point in the history
Set filename and plugins in babel options properly
  • Loading branch information
ai authored Jul 22, 2019
2 parents 52388db + dea7de9 commit abd31af
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ function expectAdjacentSibling (names) {
function loadBabelOpts (opts) {
const filename = opts.from && opts.from.replace(/\?.*$/, "");
opts = {
sourceFilename: filename,
sourceType: filename && /\.m[tj]sx?$/.test(filename) ? "module" : "unambiguous",
plugins,
allowImportExportEverywhere: true,
allowAwaitOutsideFunction: true,
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
filename,
parserOpts: {
plugins,
sourceFilename: filename,
sourceType: filename && /\.m[tj]sx?$/.test(filename) ? "module" : "unambiguous",
allowImportExportEverywhere: true,
allowAwaitOutsideFunction: true,
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
},
};
let fileOpts;
try {
Expand All @@ -126,17 +129,17 @@ function loadBabelOpts (opts) {
if (Array.isArray(fileOpts[key]) && !fileOpts[key].length) {
continue;
}
// because some options need to be passed to parser also
opts[key] = fileOpts[key];
opts.parserOpts[key] = fileOpts[key];
}
return opts;
}

function literalParser (source, opts, styles) {
let ast;
try {
ast = parse(source, {
parserOpts: loadBabelOpts(opts),
});
ast = parse(source, loadBabelOpts(opts));
} catch (ex) {
// console.error(ex);
return styles || [];
Expand Down

0 comments on commit abd31af

Please sign in to comment.