84 lines
13 KiB
JavaScript
84 lines
13 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const testcafe_hammerhead_1 = __importDefault(require("testcafe-hammerhead"));
|
|
const asyncToGenerator_1 = __importDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
const lodash_1 = require("lodash");
|
|
const load_libs_1 = __importDefault(require("./babel/load-libs"));
|
|
const runtime_1 = require("../errors/runtime");
|
|
const types_1 = require("../errors/types");
|
|
const format_babel_produced_code_1 = __importDefault(require("./babel/format-babel-produced-code"));
|
|
const get_base_babel_options_1 = __importDefault(require("./babel/get-base-babel-options"));
|
|
const ANONYMOUS_FN_RE = /^function\s*\*?\s*\(/;
|
|
const ES6_OBJ_METHOD_NAME_RE = /^(\S+?)\s*\(/;
|
|
const USE_STRICT_RE = /^('|")use strict('|");?/;
|
|
const TRAILING_SEMICOLON_RE = /;\s*$/;
|
|
const REGENERATOR_FOOTPRINTS_RE = /(_index\d+\.default|_regenerator\d+\.default|regeneratorRuntime)(\(\))?\.wrap\(function func\$\(_context\)/;
|
|
const ASYNC_TO_GENERATOR_OUTPUT_CODE = (0, format_babel_produced_code_1.default)((0, asyncToGenerator_1.default)(lodash_1.noop).toString());
|
|
const CLIENT_FUNCTION_BODY_WRAPPER = code => `const func = (${code});`;
|
|
const CLIENT_FUNCTION_WRAPPER = ({ code, dependencies }) => `(function(){${dependencies} ${code} return func;})();`;
|
|
let loadedBabelOptions = null;
|
|
function getBabelOptions() {
|
|
const { presetEnvForClientFunction, transformForOfAsArray } = (0, load_libs_1.default)();
|
|
return Object.assign({}, get_base_babel_options_1.default, {
|
|
presets: [{ plugins: [transformForOfAsArray] }, presetEnvForClientFunction],
|
|
});
|
|
}
|
|
function ensureLoadedBabelOptions() {
|
|
if (!loadedBabelOptions) {
|
|
const { babel } = (0, load_libs_1.default)();
|
|
const opts = getBabelOptions();
|
|
loadedBabelOptions = babel.loadOptions(opts);
|
|
}
|
|
return loadedBabelOptions;
|
|
}
|
|
function downgradeES(fnCode) {
|
|
const { babel } = (0, load_libs_1.default)();
|
|
const opts = ensureLoadedBabelOptions();
|
|
const compiled = babel.transform(fnCode, opts);
|
|
return compiled.code
|
|
.replace(USE_STRICT_RE, '')
|
|
.trim();
|
|
}
|
|
function getDependenciesDefinition(dependencies) {
|
|
return Object
|
|
.keys(dependencies)
|
|
.reduce((code, name) => {
|
|
return code + `var ${name}=__dependencies$['${name}'];`;
|
|
}, '');
|
|
}
|
|
function makeFnCodeSuitableForParsing(fnCode) {
|
|
// NOTE: 'function() {}' -> '(function() {})'
|
|
if (ANONYMOUS_FN_RE.test(fnCode))
|
|
return `(${fnCode})`;
|
|
// NOTE: 'myFn () {}' -> 'function myFn() {}'
|
|
const match = fnCode.match(ES6_OBJ_METHOD_NAME_RE);
|
|
if (match && match[1] !== 'function')
|
|
return `function ${fnCode}`;
|
|
return fnCode;
|
|
}
|
|
function containsAsyncToGeneratorOutputCode(code) {
|
|
const formattedCode = (0, format_babel_produced_code_1.default)(code);
|
|
return formattedCode.includes(ASYNC_TO_GENERATOR_OUTPUT_CODE);
|
|
}
|
|
function compileClientFunction(fnCode, dependencies, instantiationCallsiteName, compilationCallsiteName) {
|
|
if (containsAsyncToGeneratorOutputCode(fnCode))
|
|
throw new runtime_1.ClientFunctionAPIError(compilationCallsiteName, instantiationCallsiteName, types_1.RUNTIME_ERRORS.regeneratorInClientFunctionCode);
|
|
fnCode = makeFnCodeSuitableForParsing(fnCode);
|
|
fnCode = CLIENT_FUNCTION_BODY_WRAPPER(fnCode);
|
|
// NOTE: we need to recompile ES6 code for the browser if we are on newer versions of Node.
|
|
fnCode = downgradeES(fnCode);
|
|
fnCode = testcafe_hammerhead_1.default.processScript(fnCode, false);
|
|
// NOTE: check compiled code for regenerator injection
|
|
if (REGENERATOR_FOOTPRINTS_RE.test(fnCode))
|
|
throw new runtime_1.ClientFunctionAPIError(compilationCallsiteName, instantiationCallsiteName, types_1.RUNTIME_ERRORS.regeneratorInClientFunctionCode);
|
|
if (!TRAILING_SEMICOLON_RE.test(fnCode))
|
|
fnCode += ';';
|
|
const dependenciesDefinition = dependencies ? getDependenciesDefinition(dependencies) : '';
|
|
return CLIENT_FUNCTION_WRAPPER({ code: fnCode, dependencies: dependenciesDefinition });
|
|
}
|
|
exports.default = compileClientFunction;
|
|
module.exports = exports.default;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcGlsZS1jbGllbnQtZnVuY3Rpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29tcGlsZXIvY29tcGlsZS1jbGllbnQtZnVuY3Rpb24uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSw4RUFBNkM7QUFDN0MsK0ZBQXVFO0FBQ3ZFLG1DQUE4QjtBQUM5QixrRUFBOEM7QUFDOUMsK0NBQTJEO0FBQzNELDJDQUFpRDtBQUNqRCxvR0FBeUU7QUFDekUsNEZBQWdFO0FBRWhFLE1BQU0sZUFBZSxHQUFrQixzQkFBc0IsQ0FBQztBQUM5RCxNQUFNLHNCQUFzQixHQUFXLGNBQWMsQ0FBQztBQUN0RCxNQUFNLGFBQWEsR0FBb0IseUJBQXlCLENBQUM7QUFDakUsTUFBTSxxQkFBcUIsR0FBWSxPQUFPLENBQUM7QUFDL0MsTUFBTSx5QkFBeUIsR0FBUSw0R0FBNEcsQ0FBQztBQUNwSixNQUFNLDhCQUE4QixHQUFHLElBQUEsb0NBQXVCLEVBQUMsSUFBQSwwQkFBZ0IsRUFBQyxhQUFJLENBQUMsQ0FBQyxRQUFRLEVBQUUsQ0FBQyxDQUFDO0FBRWxHLE1BQU0sNEJBQTRCLEdBQUcsSUFBSSxDQUFDLEVBQUUsQ0FBQyxpQkFBaUIsSUFBSSxJQUFJ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