1 line
8.5 KiB
Plaintext
1 line
8.5 KiB
Plaintext
|
{"version":3,"names":["asyncGeneratorStep","gen","resolve","reject","_next","_throw","key","arg","info","value","error","done","Promise","then","_asyncToGenerator","fn","self","args","arguments","apply","err","undefined","cloneDeep","require","path","fs","babel","registerCache","nmRE","escapeRegExp","sep","string","replace","cache","transformOpts","exports","setOptions","opts","clear","load","get","extensions","Object","assign","caller","name","cwd","ignore","only","cwdRE","RegExp","transform","input","filename","loadOptionsAsync","sourceRoot","dirname","cached","store","cacheLookup","code","map","transformAsync","sourceMaps","ast","transformSync","OptionManager","init","id","cacheKey","JSON","stringify","version","env","getEnv","fileMtime","statSync","mtime","setDirty"],"sources":["../../src/worker/transform.js"],"sourcesContent":["\"use strict\";\n\nconst cloneDeep = require(\"clone-deep\");\nconst path = require(\"path\");\nconst fs = require(\"fs\");\n\nconst babel = require(\"./babel-core.js\");\nconst registerCache = require(\"../cache.js\");\n\nconst nmRE = escapeRegExp(path.sep + \"node_modules\" + path.sep);\n\nfunction escapeRegExp(string) {\n return string.replace(/[|\\\\{}()[\\]^$+*?.]/g, \"\\\\$&\");\n}\n\nlet cache;\nlet transformOpts;\nexports.setOptions = function (opts) {\n if (opts.cache === false && cache) {\n registerCache.clear();\n cache = null;\n } else if (opts.cache !== false && !cache) {\n registerCache.load();\n cache = registerCache.get();\n }\n\n delete opts.cache;\n delete opts.extensions;\n\n transformOpts = {\n ...opts,\n caller: {\n name: \"@babel/register\",\n ...(opts.caller || {}),\n },\n };\n\n let { cwd = \".\" } = transformOpts;\n\n // Ensure that the working directory is resolved up front so that\n // things don't break if it changes later.\n cwd = transformOpts.cwd = path.resolve(cwd);\n\n if (transformOpts.ignore === undefined && transformOpts.only === undefined) {\n const cwdRE = escapeRegExp(cwd);\n\n // Only compile things inside the current working directory.\n transformOpts.only = [new RegExp(\"^\" + cwdRE, \"i\")];\n // Ignore any node_modules inside the current working directory.\n transformOpts.ignore = [\n new RegExp(`^${cwdRE}(?:${path.sep}.*)?${nmRE}`, \"i\"),\n ];\n }\n};\n\nexports.transform = async function (input, filename) {\n const opts = await babel.loadOptionsAsync({\n // sourceRoot can be overwritten\n sourceRoot: path.dirname(filename) + path.sep,\n ...cloneDeep(transformOpts),\n filename,\n });\n\n // Bail out ASAP if the file has been ignored.\n if (opts === null) return null;\n\n const { cached, store } = cacheLookup(opts, filename);\n if (cached) return cached;\n\n const { code, map } = await babel.transformAsync(input, {\n ...opts,\n sourceMaps: opts.sourceMaps === undefined ? \"both\" : opts.sourceMaps,\n ast: false,\n });\n\n return store({ code, map });\n};\n\nif (!process.env.BABEL_8_BREAKING) {\n exports.transformSync = function (input, filename) {\n const opts = new babel.OptionManager().init({\n // sourceRoot can be overwritten\n sourceRoot: path.dirname(filename) + path.sep,\n ...cloneDeep(transformOpts),\n filename,\n });\n\n // Bail out ASAP if the file has been ignored.\n if (opts === null) return null;\n\n const { cached, store } = cacheLookup(opts, filename);\n if (cached) return cached;\n\n const { code, map } = babel.transformSync(input, {\n ...opts,\n sourceMaps: opts.sourceMaps === undefined ? \"both\" : opts.sourceMaps,\n ast: false,\n });\n\n return store({ code, map });\n };\n}\n\nconst id = value => value;\n\nfunction cacheLookup(opts, filename) {\n if (!cache) return { cached: null, store: id };\n\n let cacheKey = `${JSON.stringify(opts)}:${babel.version}`;\n\n const env = babel.getEnv();\n if (env) cacheKey += `:${env}`;\n\n const cached = cache[cacheKey];\n const fileMtime = +fs.statSync(filename).mtime;\n\n if (cached && cached.mtime === fileMtime) {\n return
|