Skip to content

Commit dea7de9

Browse files
author
Dmitry Sokolov
committed
Set filename and plugins in babel options properly
1 parent 52388db commit dea7de9

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

extract.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,16 @@ function expectAdjacentSibling (names) {
106106
function loadBabelOpts (opts) {
107107
const filename = opts.from && opts.from.replace(/\?.*$/, "");
108108
opts = {
109-
sourceFilename: filename,
110-
sourceType: filename && /\.m[tj]sx?$/.test(filename) ? "module" : "unambiguous",
111-
plugins,
112-
allowImportExportEverywhere: true,
113-
allowAwaitOutsideFunction: true,
114-
allowReturnOutsideFunction: true,
115-
allowSuperOutsideMethod: true,
109+
filename,
110+
parserOpts: {
111+
plugins,
112+
sourceFilename: filename,
113+
sourceType: filename && /\.m[tj]sx?$/.test(filename) ? "module" : "unambiguous",
114+
allowImportExportEverywhere: true,
115+
allowAwaitOutsideFunction: true,
116+
allowReturnOutsideFunction: true,
117+
allowSuperOutsideMethod: true,
118+
},
116119
};
117120
let fileOpts;
118121
try {
@@ -126,17 +129,17 @@ function loadBabelOpts (opts) {
126129
if (Array.isArray(fileOpts[key]) && !fileOpts[key].length) {
127130
continue;
128131
}
132+
// because some options need to be passed to parser also
129133
opts[key] = fileOpts[key];
134+
opts.parserOpts[key] = fileOpts[key];
130135
}
131136
return opts;
132137
}
133138

134139
function literalParser (source, opts, styles) {
135140
let ast;
136141
try {
137-
ast = parse(source, {
138-
parserOpts: loadBabelOpts(opts),
139-
});
142+
ast = parse(source, loadBabelOpts(opts));
140143
} catch (ex) {
141144
// console.error(ex);
142145
return styles || [];

0 commit comments

Comments
 (0)