Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
traverse(ast, {
Module: function (_Module) {
function Module(_x) {
return _Module.apply(this, arguments);
}
Module.toString = function () {
return _Module.toString();
};
return Module;
}(function (path) {
module = path.node;
})
});
var moduleContext = moduleContextFromModuleAST(module); // Transform the actual instruction in function bodies
traverse(ast, {
Func: function (_Func) {
function Func(_x2) {
return _Func.apply(this, arguments);
}
Func.toString = function () {
return _Func.toString();
};
return Func;
}(function (path) {
transformFuncPath(path, moduleContext);
}),
Start: function (_Start) {
parse(binary, state) {
// flag it as ESM
state.module.buildMeta.exportsType = "namespace";
// parse it
const program = decode(binary, decoderOpts);
const module = program.body[0];
const moduleContext = moduleContextFromModuleAST(module);
// extract imports and exports
const exports = (state.module.buildMeta.providedExports = []);
const jsIncompatibleExports = (state.module.buildMeta.jsIncompatibleExports = []);
const importedGlobals = [];
t.traverse(module, {
ModuleExport({ node }) {
const descriptor = node.descr;
if (descriptor.exportType === "Func") {
const funcidx = descriptor.id.value;
/** @type {t.FuncSignature} */
const funcSignature = moduleContext.getFunction(funcidx);
let bin = module.originalSource().source();
const initFuncId = t.identifier(
Array.isArray(module.usedExports)
? Template.numberToIdentifer(module.usedExports.length)
: "__webpack_init__"
);
// parse it
const ast = decode(bin, {
ignoreDataSection: true,
ignoreCodeSection: true,
ignoreCustomNameSection: true
});
const moduleContext = moduleContextFromModuleAST(ast.body[0]);
const importedGlobals = getImportedGlobals(ast);
const countImportedFunc = getCountImportedFunc(ast);
const startAtFuncOffset = moduleContext.getStart();
const nextFuncIndex = getNextFuncIndex(ast, countImportedFunc);
const nextTypeIndex = getNextTypeIndex(ast);
const usedDependencyMap = getUsedDependencyMap(
module,
this.options.mangleImports
);
const externalExports = new Set(
module.dependencies
.filter(d => d instanceof WebAssemblyExportImportedDependency)
.map(d => {
const wasmDep = /** @type {WebAssemblyExportImportedDependency} */ (d);
parse(binary, state) {
// flag it as ESM
state.module.buildMeta.exportsType = "namespace";
// parse it
const program = decode(binary, decoderOpts);
const module = program.body[0];
const moduleContext = moduleContextFromModuleAST(module);
// extract imports and exports
const exports = (state.module.buildMeta.providedExports = []);
const jsIncompatibleExports = (state.module.buildMeta.jsIncompatibleExports = []);
const importedGlobals = [];
t.traverse(module, {
ModuleExport({ node }) {
const descriptor = node.descr;
if (descriptor.exportType === "Func") {
const funcidx = descriptor.id.value;
/** @type {t.FuncSignature} */
const funcSignature = moduleContext.getFunction(funcidx);
let bin = module.originalSource().source();
const initFuncId = t.identifier(
Array.isArray(module.usedExports)
? Template.numberToIdentifer(module.usedExports.length)
: "__webpack_init__"
);
// parse it
const ast = decode(bin, {
ignoreDataSection: true,
ignoreCodeSection: true,
ignoreCustomNameSection: true
});
const moduleContext = moduleContextFromModuleAST(ast.body[0]);
const importedGlobals = getImportedGlobals(ast);
const countImportedFunc = getCountImportedFunc(ast);
const startAtFuncOffset = moduleContext.getStart();
const nextFuncIndex = getNextFuncIndex(ast, countImportedFunc);
const nextTypeIndex = getNextTypeIndex(ast);
const usedDependencyMap = getUsedDependencyMap(
module,
this.options.mangleImports
);
const externalExports = new Set(
module.dependencies
.filter(d => d instanceof WebAssemblyExportImportedDependency)
.map(d => {
const wasmDep = /** @type {WebAssemblyExportImportedDependency} */ (d);
let bin = module.originalSource().source();
const initFuncId = t.identifier(
Array.isArray(module.usedExports)
? Template.numberToIdentifer(module.usedExports.length)
: "__webpack_init__"
);
// parse it
const ast = decode(bin, {
ignoreDataSection: true,
ignoreCodeSection: true,
ignoreCustomNameSection: true
});
const moduleContext = moduleContextFromModuleAST(ast.body[0]);
const importedGlobals = getImportedGlobals(ast);
const countImportedFunc = getCountImportedFunc(ast);
const startAtFuncOffset = moduleContext.getStart();
const nextFuncIndex = getNextFuncIndex(ast, countImportedFunc);
const nextTypeIndex = getNextTypeIndex(ast);
const usedDependencyMap = getUsedDependencyMap(
module,
this.options.mangleImports
);
const externalExports = new Set(
module.dependencies
.filter(d => d instanceof WebAssemblyExportImportedDependency)
.map(d => {
const wasmDep = /** @type {WebAssemblyExportImportedDependency} */ (d);
modules.forEach(m => {
const moduleContext = moduleContextFromModuleAST(m);
// $FlowIgnore
errors.push(...imports(ast, moduleContext));
errors.push(...isConst(ast, moduleContext));
errors.push(...importOrderValidate(ast));
errors.push(...typeChecker(ast, moduleContext));
errors.push(...duplicatedExports(ast));
});
export default function validate(ast) {
if (!ast.body || !ast.body[0] || !ast.body[0].fields) {
return [];
}
// Module context
const moduleContext = moduleContextFromModuleAST(ast.body[0]);
const typeChecker = createTypeChecker();
// Simulate stack types throughout all function bodies
traverse(ast, {
Func({ node }) {
typeChecker.setStopFuncCheck(false);
typeChecker.setCurrentFuncName(node.name.value);
// resolve signature
let signature;
{
// signature might be a reference to a type
if (isSignature(node.signature)) {
signature = node.signature;
} else {
bin = preprocess(bin);
const initFuncId = t.identifier(
Array.isArray(module.usedExports)
? Template.numberToIdentifer(module.usedExports.length)
: "__webpack_init__"
);
// parse it
const ast = decode(bin, {
ignoreDataSection: true,
ignoreCodeSection: true,
ignoreCustomNameSection: true
});
const moduleContext = moduleContextFromModuleAST(ast.body[0]);
const importedGlobals = getImportedGlobals(ast);
const countImportedFunc = getCountImportedFunc(ast);
const startAtFuncOffset = moduleContext.getStart();
const nextFuncIndex = getNextFuncIndex(ast, countImportedFunc);
const nextTypeIndex = getNextTypeIndex(ast);
const usedDependencyMap = getUsedDependencyMap(
module,
this.options.mangleImports
);
const externalExports = new Set(
module.dependencies
.filter(d => d instanceof WebAssemblyExportImportedDependency)
.map(d => d.exportName)
);