oxc-project / backlog

backlog for collborators only
1 stars 0 forks source link

Provide API for reading source text from disk into a buffer #94

Open overlookmotel opened 2 months ago

overlookmotel commented 2 months ago

The most common use case for Oxc is reading a file from disk and parsing it.

Currently the parser takes a &str. We could add an API to read a file from disk into a SourceText buffer which is then passed to parser. Possibly SourceText would store the data in the arena.

There's a few advantages to this:

  1. If you reuse the same SourceText buffer over and over when parsing many files, that'd likely be a perf gain, as source text would always be in a block of memory which is warm in the cache.
  2. It'd remove the cost of string copying for #20.
  3. It'd be useful for AST transfer for the source text to be in the arena - could make for more efficient code for extracting strings from the serialized buffer.