esnode/visitor.js
/**
 * Create literal with resolved path.
 *
 * @param program Ts program.
 * @param ctx Transformation context.
 * @param path Path to be processed.
 * @return String literal.
 */
Create literal with resolved path.
@param program Ts program.
@param ctx Transformation context.
@param path Path to be processed.
@return String literal.
Create literal with resolved path . @param program Ts program . @param ctx Transformation context . @param path Path to be processed . @return String literal .
function createPathLiteral({ program, context, sourceFile, pluginConfig, path }) {
    const compilerOptions = context.getCompilerOptions();
    if (!cachedPaths.has(path)) {
        const output = resolve_1.resolvePath({
            path,
            scan: pluginConfig.scan,
            file: sourceFile.fileName,
            root: compilerOptions.baseUrl,
            files: program.getSourceFiles().map(({ fileName }) => fileName),
            globs: Object.keys(compilerOptions.paths).map(alias => ({
                alias: createWildcard(alias),
                paths: compilerOptions.paths[alias].map(createWildcard)
            }))
        });
        if (!output) {
            throw new Error('Resolved path must exist');
        }
        cachedPaths.set(path, output);
    }
    return ts.createLiteral(cachedPaths.get(path));
}
function createPathLiteral ( { program , context , sourceFile , pluginConfig , path } ) { const compilerOptions = context . getCompilerOptions ( ) ; if ( ! cachedPaths . has ( path ) ) { const output = resolve_1 . resolvePath ( { path , scan : pluginConfig . scan , file : sourceFile . fileName , root : compilerOptions . baseUrl , files : program . getSourceFiles ( ) . map ( ( { fileName } ) => fileName ) , globs : Object . keys ( compilerOptions . paths ) . map ( alias => ( { alias : createWildcard ( alias ) , paths : compilerOptions . paths [ alias ] . map ( createWildcard ) } ) ) } ) ; if ( ! output ) { throw new Error ( 'Resolved path must exist' ) ; } cachedPaths . set ( path , output ) ; } return ts . createLiteral ( cachedPaths . get ( path ) ) ; }
Create literal with resolved path.
Create literal with resolved path .
// Compiler options used to generate code. // Check for the path in the cache. // Resolve path // Path to be resolved. // Scan sources. // File location which include node. // Path mapping root. // List of found sources. // Patterns used to resolve path. // Verify output. // Remember resolved path.