@pika/pack
Version:
package building, reimagined.
21 lines (20 loc) • 698 B
JavaScript
// @flow
import chalk from 'chalk';
function getLineCol(node) {
const loc = node.loc.start;
return chalk.dim(`[${loc.line}:${loc.column}]`);
}
export function validateDynamicImportArguments(path) {
if (path.parent.arguments.length !== 1) {
return new Set([
`${getLineCol(path.node)} "\`import()\` only accepts 1 argument, but got ${path.parent.arguments.length}`,
]);
}
const [argNode] = path.parent.arguments;
if (argNode.type !== 'StringLiteral') {
return new Set([
`${getLineCol(path.node)} Pika expects strings as \`import()\` arguments. Treating this as an absolute file path.`,
]);
}
return new Set();
}