Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
imports.forEach(importName => {
const source = getSource(state.source, importName);
if (!importMap[importName]) {
if (!sourceMap[source]) {
// var _react = require("react")
sourceMap[source] = addNamespace(path, source, {
importedInterop: "uncompiled",
ensureLiveReference: true,
}).name;
}
importMap[importName] = sourceMap[source];
}
});
return importMap;
imports.forEach((imp) => {
const identifier = identifiers[imp.moduleName] = identifiers[imp.moduleName] || babelModuleImports.addNamespace(path, imp.moduleName);
imp.path.parentPath.replaceWithSourceString(`Promise.resolve(${identifier.name})`);
});
},
callExpression.typeParameters.params.length !== 1
) {
throw new MacroError(
"Macro should be called as a function and passed exactly one type parameter",
);
}
const macroArgument = callExpression.arguments[0];
if (!t.isIdentifier(macroArgument)) {
throw new MacroError(
"For now, this macro works with identifiers only, sorry",
);
}
const generatedImport = addNamespace(path, "generic-type-guard");
if (!t.isIdentifier(generatedImport)) {
throw new MacroError("Something wrong happened at our side, sorry");
}
const expectedType = callExpression.typeParameters.params[0];
const identifier = macroArgument.name;
const generatedCode = `(${typeToPartialGuard(
expectedType,
generatedImport.name,
)})(${identifier})`;
const generatedAst = parser.parse(generatedCode);
path.parentPath.replaceWith(generatedAst.program.body[0]);
}
}