/
githubmirror
/
amphtml
Обзор
Документация
Войти
/
githubmirror
/
amphtml
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/compiler/compile.ts
26 строк
829 B
Jake Fried
compiler: use .ts files (#37370)
18 янв 2022, 21:34
Не верифицирован
18 янв 2022, 21:34
5494590
Код
Авторство
О чём код?
import * as compiler from '@ampproject/bento-compiler'; import {getBuilders} from './builders'; import type {CompilerRequest, CompilerResponse} from './types'; const missingPropErrorMsg = 'Must provide component_versions and either document or nodes'; /** * Returns the AST for an AMP Document with eligible components server-rendered. */ export function compile(request: CompilerRequest): CompilerResponse { const {component_versions: versions, document, nodes} = request ?? {}; if (!versions) { throw new Error(missingPropErrorMsg); } const builders = getBuilders(versions); if (document) { return {document: compiler.renderAstDocument(document, builders)}; } else if (nodes) { return {nodes: compiler.renderAstNodes(nodes, builders)}; } else { throw new Error(missingPropErrorMsg); } }