UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

34 lines (32 loc) 1.41 kB
import { tsUtils } from '@neo-one/ts-utils'; import { normalizePath } from '@neo-one/utils'; import _ from 'lodash'; import { compile } from './compile'; import { createContextForPath, updateContext } from './createContext'; import { transpile } from './transpile'; export const compileContract = ({ filePath: filePathIn, host, linked: linkedIn = {}, }) => { const filePath = normalizePath(filePathIn); const linked = _.fromPairs(Object.entries(linkedIn).map(([key, value]) => [normalizePath(key), value])); const transpileContext = createContextForPath(filePath, host); const transpileResult = transpile({ sourceFile: tsUtils.file.getSourceFileOrThrow(transpileContext.program, filePath), context: transpileContext, }); const context = transpileResult === undefined ? transpileContext : updateContext(transpileContext, { [filePath]: transpileResult.text }); const { abi, sourceMap: finalSourceMap, contract, debugInfo } = compile({ sourceFile: tsUtils.file.getSourceFileOrThrow(context.program, filePath), context, linked, sourceMaps: transpileResult === undefined ? {} : { [filePath]: transpileResult.sourceMap }, }); return { diagnostics: context.diagnostics, sourceMap: finalSourceMap, abi, contract, debugInfo, }; }; //# sourceMappingURL=compileContract.js.map