Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const buildDeclareExports = template(`
var ${exportName} = {
__esModule: true
};
`);
// Uses 'var' since it gets added during wrap
export const buildTempExport = template(`
var ${exportName} = VALUE;
`);
export const buildExportDefault = template(`
export default VALUE;
`);
export const buildReturnExports = template(`
return ${exportName};
`);
export function buildNamedExport(obj) {
return buildAssign({
OBJECT: exportsIdentifier,
NAME: obj.key,
VALUE: obj.value,
});
}
export const buildAllExportHelper = template(`
function extendExports(exports, obj) {
Object.keys(obj).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
`);
export const buildReturn = template(`
return ID;
`);
export const buildDefaultImportInterop = template(`
function _interopRequireDefault(obj) { return (obj && obj.__esModule && typeof obj.default !== "undefined") ? obj.default : obj; }
`);
export const buildDefaultImportDeconstructor = template(`
const LOCAL = _interopRequireDefault(MODULE);
`);
// TODO: inject __extends instead of Object.assign unless useBuiltIns in set
export const buildDynamicImportHelper = template(`
function __ui5_require_async(path) {
return new Promise((resolve, reject) => {
sap.ui.require([path], (module) => {
if (!module) {
return reject("No module returned from " + path);
} else if (module.__esModule) {
return resolve(module);
} else if (module.default) {
return reject(new Error(path + " module includes a 'default' property but not __esModule. Cannot use as dynamic import"));
} else {
module.default = typeof module === "object" ? Object.assign({}, module) : module;
module.__esModule = true;
resolve(module);
}
})
})
import { template, types as t } from "@babel/core";
const buildRest = template(`
for (var LEN = ARGUMENTS.length,
ARRAY = new Array(ARRAY_LEN),
KEY = START;
KEY < LEN;
KEY++) {
ARRAY[ARRAY_KEY] = ARGUMENTS[KEY];
}
`);
const restIndex = template(`
(INDEX < OFFSET || ARGUMENTS.length <= INDEX) ? undefined : ARGUMENTS[INDEX]
`);
const restIndexImpure = template(`
REF = INDEX, (REF < OFFSET || ARGUMENTS.length <= REF) ? undefined : ARGUMENTS[REF]
`);
const restLength = template(`
ARGUMENTS.length <= OFFSET ? 0 : ARGUMENTS.length - OFFSET
`);
function referencesRest(path, state) {
if (path.node.name === state.name) {
// Check rest parameter is not shadowed by a binding in another scope.
return path.scope.bindingIdentifierEquals(state.name, state.outerBinding);
}
const exportName = "__exports";
export const exportsIdentifier = t.identifier(exportName);
export const buildAssign = template(`
OBJECT.NAME = VALUE;
`);
export const buildDefine = template(`
sap.ui.define(SOURCES, function (PARAMS) {
BODY;
});
`);
export const buildDefineGlobal = template(`
sap.ui.define(SOURCES, function (PARAMS) {
BODY;
}, true);
`);
// Uses 'var' since it gets added during wrap
export const buildDeclareExports = template(`
var ${exportName} = {
__esModule: true
};
`);
// Uses 'var' since it gets added during wrap
export const buildTempExport = template(`
var ${exportName} = VALUE;
`);
return obj[key];
}
});
});
}
`);
export const buildAllExport = template(`
extendExports(${exportName}, LOCAL);
`);
export const buildReturn = template(`
return ID;
`);
export const buildDefaultImportInterop = template(`
function _interopRequireDefault(obj) { return (obj && obj.__esModule && typeof obj.default !== "undefined") ? obj.default : obj; }
`);
export const buildDefaultImportDeconstructor = template(`
const LOCAL = _interopRequireDefault(MODULE);
`);
// TODO: inject __extends instead of Object.assign unless useBuiltIns in set
export const buildDynamicImportHelper = template(`
function __ui5_require_async(path) {
return new Promise((resolve, reject) => {
sap.ui.require([path], (module) => {
if (!module) {
return reject("No module returned from " + path);
} else if (module.__esModule) {
return resolve(module);
resolve(module);
}
})
})
}
`);
export const buildConstDeclaration = template(`
const NAME = VALUE;
`);
export const buildNamedImportDestructor = template(`
const LOCAL = MODULE[IMPORTED];
`);
export const buildExtendAssign = template(`
const NAME = SUPER.extend(FQN, OBJECT);
`);
// This is use when there is not already the function, so always propagate arguments.
export const buildInheritingFunction = template(`
function NAME() {
if (typeof SUPER.prototype.NAME === 'function') {
SUPER.prototype.NAME.apply(this, arguments);
}
}
`);
// This is use when there is not already the function, so always propagate arguments.
export const buildInheritingConstructor = template(`
function constructor() {
SUPER.prototype.constructor.apply(this, arguments);
export const buildDefineGlobal = template(`
sap.ui.define(SOURCES, function (PARAMS) {
BODY;
}, true);
`);
// Uses 'var' since it gets added during wrap
export const buildDeclareExports = template(`
var ${exportName} = {
__esModule: true
};
`);
// Uses 'var' since it gets added during wrap
export const buildTempExport = template(`
var ${exportName} = VALUE;
`);
export const buildExportDefault = template(`
export default VALUE;
`);
export const buildReturnExports = template(`
return ${exportName};
`);
export function buildNamedExport(obj) {
return buildAssign({
OBJECT: exportsIdentifier,
NAME: obj.key,
VALUE: obj.value,
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return obj[key];
}
});
});
}
`);
export const buildAllExport = template(`
extendExports(${exportName}, LOCAL);
`);
export const buildReturn = template(`
return ID;
`);
export const buildDefaultImportInterop = template(`
function _interopRequireDefault(obj) { return (obj && obj.__esModule && typeof obj.default !== "undefined") ? obj.default : obj; }
`);
export const buildDefaultImportDeconstructor = template(`
const LOCAL = _interopRequireDefault(MODULE);
`);
// TODO: inject __extends instead of Object.assign unless useBuiltIns in set
export const buildDynamicImportHelper = template(`
function __ui5_require_async(path) {
return new Promise((resolve, reject) => {
sap.ui.require([path], (module) => {
export default VALUE;
`);
export const buildReturnExports = template(`
return ${exportName};
`);
export function buildNamedExport(obj) {
return buildAssign({
OBJECT: exportsIdentifier,
NAME: obj.key,
VALUE: obj.value,
});
}
export const buildAllExportHelper = template(`
function extendExports(exports, obj) {
Object.keys(obj).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return obj[key];
}
});
});
}
`);
export const buildAllExport = template(`
extendExports(${exportName}, LOCAL);
`);
import { declare } from "@babel/helper-plugin-utils";
import hoistVariables from "@babel/helper-hoist-variables";
import { template, types as t } from "@babel/core";
import { getImportSource } from "babel-plugin-dynamic-import-node/utils";
const buildTemplate = template(`
SYSTEM_REGISTER(MODULE_NAME, SOURCES, function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) {
"use strict";
BEFORE_BODY;
return {
setters: SETTERS,
execute: function () {
BODY;
}
};
});
`);
const buildExportAll = template(`
for (var KEY in TARGET) {
if (KEY !== "default" && KEY !== "__esModule") EXPORT_OBJ[KEY] = TARGET[KEY];
}