Skip to content

Commit

Permalink
Reversing corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
esseswann committed Sep 30, 2023
1 parent 55d6757 commit 331ca5b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/metadata/compileViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export async function* compileViews(
const templateLikeView = await getTemplate(dirent)
templates.set(name, templateLikeView)
const sections = compileTemplate(templates, new Set(), name)!
sections.declares = new Map([...sections.declares].reverse())
templates.delete(name)
unusedTemplates.push(...resetTemplates(templates))
const result = compileDeclares(sections.declares) + sections.body
Expand Down
12 changes: 7 additions & 5 deletions src/metadata/templateSections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const extractSections = (view: string): TemplateSections => {
if (match.groups) declares.set(match[1], match.groups as Declare)

const body = cleanQuery(view.replace(declaresRegex, '').trim())
console.log(body)

return { declares, body }
}
Expand All @@ -27,16 +28,17 @@ export const mergeDeclares = (left: Declares, right: Declares) => {
}

export const compileDeclares = (declares: Declares) => {
const result: string[] = []
for (const declare of declares) result.push(compileDeclare(declare))
return result.join(';')
let result = ''
console.log('comipleDeclares', declares)
for (const declare of declares) result += compileDeclare(declare)
return result
}

const compileDeclare = (declare: [string, Declare]): string => {
const [key, { type, defaultValue }] = declare
let base = `declare ${key} as ${type}`
let base = `declare $${key} as ${type}`
if (defaultValue) base += ` = ${defaultValue}`
return base
return `${base};`
}

export type TemplateSections = {
Expand Down

0 comments on commit 331ca5b

Please sign in to comment.