Not in this alpha
This feature is not included in Tyhp 805.0.0-alpha.1 (roadmap Tier 2/3). The rest of this page describes the planned design. Do not expect these commands or syntax to work yet.
Tier 2 · Story 17Planned
This feature is not included in Tyhp 805.0.0-alpha.1 (roadmap Tier 2/3). The rest of this page describes the planned design. Do not expect these commands or syntax to work yet.
Source maps provide a bidirectional mapping between positions in the compiled PHP output and their originating positions in the original Tyhp source files. They enable debugging with your .tyhp files while PHP executes the compiled output, and allow tools to map PHP runtime errors back to Tyhp source locations.
Tyhp generates source maps using the Source Map v3 specification (the same format used by JavaScript/TypeScript tooling). Each .php output file gets a corresponding .php.map file containing a JSON document with the mapping data.
{
"version": 3,
"file": "User.php",
"sourceRoot": "../src/",
"sources": ["Models/User.tyhp"],
"sourcesContent": [null],
"names": [],
"mappings": "AAAA;AACA,SAAS,..."
}
The mappings field contains VLQ Base64-encoded position data that maps each segment of the generated PHP code back to a position in the original Tyhp source.
Source maps are generated as part of the tyhp build process. Enable them in your tyhp.json configuration:
{
"build": {
"generateSourcemap": true
}
}
When enabled, the build action generates a .php.map file alongside each compiled .php file:
build/
App/
Models/
User.php
User.php.map
Services/
Auth.php
Auth.php.map
When source maps are generated, the compiler appends a sourceMappingURL comment to the end of each compiled PHP file, linking it to its source map:
<?php
declare(strict_types=1);
namespace App\Models;
class User {
// ... compiled code ...
}
//# sourceMappingURL=User.php.map
As an alternative to external .php.map files, source maps can be embedded directly in the PHP output as a base64 data URL comment. This avoids the need for separate .map files but increases the size of the PHP output. This mode is available for special use cases but external source maps are recommended for most workflows.
Source maps are consumed by several Tyhp tools:
The Tyhp compiler includes a source map validator that can verify the correctness of generated source maps. It checks VLQ encoding integrity, mapping coverage, source index bounds, and line count consistency. Validation can be enabled during builds for quality assurance.
Source map generation adds a small amount of overhead to the build process. If you do not need debugging support or source-mapped error reporting, leave build.generateSourcemap set to false for the fastest builds.