Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Source Span Laravel Package

scssphp/source-span

scssphp/source-span is a small PHP utility for tracking and working with source code spans (start/end positions) used by scssphp and related tooling. Useful for mapping errors, locations, and ranges back to the original source during parsing and compilation.

View on GitHub
Deep Wiki
Context7

Getting Started

  • This package is a low-level utility for representing source locations and spans — it’s a dependency of scssphp/scssphp but can be used independently for tooling, diagnostics, or custom SCSS/Sass compilers.
  • Start by installing via Composer: composer require scssphp/source-span.
  • The core classes are SourceSpan and SourceFile. A SourceSpan represents a contiguous slice of text in a SourceFile, with start/end positions (line/column-based).
  • First use case: map errors or warnings back to original source when compiling SCSS.

Implementation Patterns

  • Use SourceFile::create() to represent a source file by name and contents.
  • Construct SourceSpan objects via SourceSpan::create($file, $start, $end) — positions are Position objects (with line, column, byteOffset).
  • Ideal for building diagnostic tools: emit SourceSpan instances alongside error messages (e.g., in custom Sass functions or custom rule linters).
  • Common pattern: integrate with custom SCSS compiler plugins or AST processors that need to track and report precise locations (e.g., @error messages or IDE language server integrations).
  • When working with source maps or transformations, SourceSpan can be mapped to original sources using position remapping logic.

Gotchas and Tips

  • SourceSpan is immutable — always create new instances when positions change.
  • Positions use 1-based line and column indices — verify alignment with your parser or editor (many tools use 0-based internally, leading to off-by-one bugs).
  • SourceSpan::toString() returns the substring content; use getSourceCode() to access full source if needed.
  • The package is minimal — no built-in pretty-printing or error rendering — implement your own formatter (or extend with php-http/message-factory for HTTP diagnostics).
  • Check for null spans (e.g., optional metadata) and validate that spans are within file bounds before rendering to avoid runtime exceptions.
  • As a standalone utility, ensure your higher-level compiler or tool manages span lifetimes and file references carefully — especially if reusing SourceFile instances across multiple compilations.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle