From b3f1da6cda607fcb0704908da8f7232ff60057e0 Mon Sep 17 00:00:00 2001 From: Gianluca Guarini Date: Fri, 29 Nov 2024 23:25:29 +0100 Subject: [PATCH] updated: types --- compiler.d.ts | 8 +++++++- src/utils/pre-process-source.js | 5 +++-- test/core.spec.js | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/compiler.d.ts b/compiler.d.ts index f442d6f..de523aa 100644 --- a/compiler.d.ts +++ b/compiler.d.ts @@ -54,7 +54,13 @@ export function generateSlotsFromString( ): string export function compile( - source: string, + source: + | string + // TODO: re use the parser types as soon as they will be available + | { + output: { template: unknonw; script: unknown; style: unknown } + data: string + }, options?: CompilerOptions, ): CompilerOutput diff --git a/src/utils/pre-process-source.js b/src/utils/pre-process-source.js index 2bbe36a..7710f4d 100644 --- a/src/utils/pre-process-source.js +++ b/src/utils/pre-process-source.js @@ -6,14 +6,15 @@ import { execute as runPreprocessor } from '../preprocessors.js' /** * Get an object containing the template, css and javascript ast. The origianl source code and the sourcemap are also included * - * @param { string | ParserResult.Output } source - source code of the tag we will need to compile or a parsed Component AST + * @param { string | ParserResult } source - source code of the tag we will need to compile or a parsed Component AST * @param { Object } meta - compiler meta object that will be used to store the meta information of the input across the whole compilation * @returns { Object } object that will be used to generate the output code */ export default function preProcessSource(source, meta) { // if the source is a parser output we can return it directly // @link https://github.com/riot/compiler/issues/178 - if (isObject(source)) return { ...source, code: '', map: null } + if (isObject(source)) + return { ...source.output, code: source.data, map: null } const { options } = meta diff --git a/test/core.spec.js b/test/core.spec.js index 8e771cd..1fa1dd7 100644 --- a/test/core.spec.js +++ b/test/core.spec.js @@ -43,7 +43,7 @@ describe('Core specs', () => { it('The compiler accepts also parsed components AST', async function () { const { parse } = riotParser() const parserResult = parse(getFixture('my-component.riot')) - const result = compile(parserResult.output) + const result = compile(parserResult) const output = evaluateScript(result.code) expect(result.code).to.be.a('string')