importLine
tcmts.loader.importLine · #gsmv2yw2 · term · runs anywhere
export function importLine(local: string, exported: string, from: string, typeOnly: boolean): string {
const t = typeOnly ? "type " : "";
if (exported === "default") return `import ${t}${local} from ${JSON.stringify(from)};`;
if (exported === "*") return `import ${t}* as ${local} from ${JSON.stringify(from)};`;
// a name that isn't an identifier (a file's: `getting-started`) is imported by its name in quotes
const name = /^[A-Za-z_$][\w$]*$/.test(exported) ? exported : JSON.stringify(exported);
return `import ${t}{ ${exported === local ? local : `${name} as ${local}`} } from ${JSON.stringify(from)};`;
}
used by