MCPcopy Create free account
hub / github.com/ampproject/amphtml / transformContents

Function transformContents

build-system/common/esbuild-babel.js:53–76  ·  view source on GitHub ↗

* @param {string} filename * @param {string} contents * @param {string} hash * @param {object} babelOptions * @return {!Promise<!CacheMessageDef>}

(filename, contents, hash, babelOptions)

Source from the content-addressed store, hash-verified

51 * @return {!Promise<!CacheMessageDef>}
52 */
53 async function transformContents(filename, contents, hash, babelOptions) {
54 if (enableCache) {
55 if (!transformCache) {
56 transformCache = new TransformCache('.babel-cache');
57 }
58 const cached = transformCache.get(hash);
59 if (cached) {
60 return cached;
61 }
62 }
63
64 const promise = babel
65 .transformAsync(contents, babelOptions)
66 .then((result) => {
67 const {code, map} = /** @type {!babel.BabelFileResult} */ (result);
68 return {filename, code: code || '', map};
69 });
70
71 if (enableCache) {
72 transformCache.set(hash, promise);
73 }
74
75 return promise;
76 }
77
78 return {
79 name: 'babel',

Callers 1

setupFunction · 0.85

Calls 3

getMethod · 0.45
thenMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected