Skip to content

Commit

Permalink
updated: types
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Nov 29, 2024
1 parent 5b1868d commit b3f1da6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 7 additions & 1 deletion compiler.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/utils/pre-process-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit b3f1da6

Please sign in to comment.