Curvea

Advanced

Parser Internals

The parser entry is:

src/parser/parseCurveaScriptFile.js

The exported function is:

parseCurveaScriptFile(source)

Returned structure

The parser returns an object with fields such as:

{
  kind,
  name,
  props,
  layout,
  imports,
  loads,
  paginate,
  data,
  seo,
  styles,
  scripts,
  body
}

File declaration detection

The parser recognizes:

@page
@layout Name(...)
@component Name(...)
@document

Only one declaration is allowed.

Page layout directive

The parser recognizes page layout usage through:

@use Main(title=page.title)

Only one @use directive is allowed in a page.

Top-level directive behavior

The parser only treats several directives specially when flowDepth === 0.

This prevents directives inside @if and @for blocks from being incorrectly extracted as file-level directives.

Block parsing

The parser handles block directives such as:

@data
@end
@seo
@end
@style
@end
@script
@end

Raw code

The parser preserves @code ... @endcode blocks in the body so the resolver can protect them later.

Error examples

The parser throws errors for:

  • missing file declaration
  • multiple file declarations
  • page content before @page
  • invalid declarations
  • invalid props
  • invalid @use
  • invalid @load
  • invalid @paginate
  • unclosed blocks