Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcemaps WIP #432

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Sourcemaps WIP #432

wants to merge 12 commits into from

Conversation

dschuff
Copy link
Member

@dschuff dschuff commented May 12, 2017

Not ready to go yet, but just to get this up here.
API is a little rough, and no support for serialization/deserialization yet, but has the basic functions of adding mappings and generating segments. Also tests.

@dschuff
Copy link
Member Author

dschuff commented May 12, 2017

Most of the way to printing. TODO: VLQs, parsing. Now would be a good time for a round of review.

@binji
Copy link
Member

binji commented May 12, 2017

Sorry, got started looking at this then got distracted. :-)

Copy link
Member

@binji binji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, I didn't realize all the neat ways you can use the {} initialization syntax!

assert(map.segment_groups.empty() ||
mapping.generated.line > last_gen_line); // Not sorted.
while (++last_gen_line <= mapping.generated.line) {
map.segment_groups.push_back(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not emplace_back and drop the {}?

return true;
}

static int32_t cmpLocation(const SourceMapGenerator::SourceLocation& a,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're still pretty inconsistent, but I think this should eventually be CmpLocation

bool SourceMap::Validate(bool fatal) const {
for (size_t i = 0; i < segment_groups.size(); ++i) {
const auto& group = segment_groups[i];
if (i > 0 && group.generated_line <= segment_groups[i - 1].generated_line) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been writing this sort of thing as CHECK_FOO(<cond>) -- I find it more readable, but curious what you think.

uint32_t last_source_line = 0;
uint32_t last_source_col = 0;
map.segment_groups.clear();
const SourceMapGenerator::SourceMapping* last_mapping = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could drop SourceMapGenerator right?

private:
void CompressMappings();

bool map_prepared = false; // Is the map compressed and ready for export?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently seems to be unused?

}

void SourceMapGenerator::CompressMappings() {
std::sort(mappings.begin(), mappings.end());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's convenient for being self contained, but how likely are we to add mappings out of order? Seems like a lot of this could be simplified if we could assume that AddMapping only can add mappings in order.

// Representation of mappings
struct Segment {
// Field 1
uint32_t generated_col = 0; // Start column in generated code. Remove?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems like these aren't really necessary since you can always calculate them. Maybe better to just add functions if they're needed?

}

void SourceMapGenerator::DumpRawMappings() {
std::sort(mappings.begin(), mappings.end());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit weird that a dumping function would modify the mappings.

TEST(source_maps, serialization_empty) {
SourceMapGenerator smg("source.out", "source-root");
std::string output = smg.SerializeMappings();
EXPECT_JSON_CONTAINS_NUM(output, "version", "3");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like it would be better to just parse the json here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants