Description
echo 'x = 1' | hcl2tojson - --with-meta
# → {"x": 1}
# Expected: {"x": 1, "__start_line__": 1, "__end_line__": 1}
The --with-meta flag is accepted without error but the output contains no __start_line__ / __end_line__ keys.
Root Cause
The with_meta option is a stub that was never wired up during the v8 architecture overhaul:
cli/hcl_to_json.py defines the flag and passes it to SerializationOptions ✓
hcl2/utils.py defines with_meta: bool = False on the dataclass ✓
- No
serialize() method in rules/base.py ever checks options.with_meta ✗
- The metadata (
line, end_line, column, end_column) exists on every LarkRule._meta — it's just never written to the output dict
hcl2/const.py is missing START_LINE_KEY / END_LINE_KEY constants
- Tests only verify the flag is accepted without error, not that output contains metadata
Expected Behavior
When --with-meta is passed, every attribute and block in the output dict should include __start_line__ and __end_line__ keys sourced from LarkRule._meta.
Workaround
Use hq --with-location which correctly provides line/column metadata.
Suggested Fix
Each serialize() method (AttributeRule, BlockRule, etc.) needs to check if options.with_meta: and inject __start_line__ / __end_line__ keys from self._meta. Add corresponding constants to hcl2/const.py.
Related: #130
Description
The
--with-metaflag is accepted without error but the output contains no__start_line__/__end_line__keys.Root Cause
The
with_metaoption is a stub that was never wired up during the v8 architecture overhaul:cli/hcl_to_json.pydefines the flag and passes it toSerializationOptions✓hcl2/utils.pydefineswith_meta: bool = Falseon the dataclass ✓serialize()method inrules/base.pyever checksoptions.with_meta✗line,end_line,column,end_column) exists on everyLarkRule._meta— it's just never written to the output dicthcl2/const.pyis missingSTART_LINE_KEY/END_LINE_KEYconstantsExpected Behavior
When
--with-metais passed, every attribute and block in the output dict should include__start_line__and__end_line__keys sourced fromLarkRule._meta.Workaround
Use
hq --with-locationwhich correctly provides line/column metadata.Suggested Fix
Each
serialize()method (AttributeRule,BlockRule, etc.) needs to checkif options.with_meta:and inject__start_line__/__end_line__keys fromself._meta. Add corresponding constants tohcl2/const.py.Related: #130