source: imaps-frontend/node_modules/babel-loader/lib/transform.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.2 KB
Line 
1const babel = require("@babel/core");
2const {
3 promisify
4} = require("util");
5const LoaderError = require("./Error");
6const transform = promisify(babel.transform);
7module.exports = async function (source, options) {
8 let result;
9 try {
10 result = await transform(source, options);
11 } catch (err) {
12 throw err.message && err.codeFrame ? new LoaderError(err) : err;
13 }
14 if (!result) return null;
15
16 // We don't return the full result here because some entries are not
17 // really serializable. For a full list of properties see here:
18 // https://github.com/babel/babel/blob/main/packages/babel-core/src/transformation/index.js
19 // For discussion on this topic see here:
20 // https://github.com/babel/babel-loader/pull/629
21 const {
22 ast,
23 code,
24 map,
25 metadata,
26 sourceType,
27 externalDependencies
28 } = result;
29 if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
30 map.sourcesContent = [source];
31 }
32 return {
33 ast,
34 code,
35 map,
36 metadata,
37 sourceType,
38 // Convert it from a Set to an Array to make it JSON-serializable.
39 externalDependencies: Array.from(externalDependencies || [])
40 };
41};
42module.exports.version = babel.version;
Note: See TracBrowser for help on using the repository browser.