Skip to content

Sourcemaps WIP - #432

Open
dschuff wants to merge 12 commits into
mainfrom
sourcemaps
Open

Sourcemaps WIP#432
dschuff wants to merge 12 commits into
mainfrom
sourcemaps

Conversation

@dschuff

@dschuff dschuff commented May 12, 2017

Copy link
Copy Markdown
Member

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

dschuff commented May 12, 2017

Copy link
Copy Markdown
Member Author

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

@binji

binji commented May 12, 2017

Copy link
Copy Markdown
Member

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

@binji binji left a comment

Copy link
Copy Markdown
Member

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!

Comment thread src/source-maps.cc
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
Copy Markdown
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 {}?

Comment thread src/source-maps.cc
return true;
}

static int32_t cmpLocation(const SourceMapGenerator::SourceLocation& a,

Copy link
Copy Markdown
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

Comment thread src/source-maps.cc
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
Copy Markdown
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.

Comment thread src/source-maps.cc
uint32_t last_source_line = 0;
uint32_t last_source_col = 0;
map.segment_groups.clear();
const SourceMapGenerator::SourceMapping* last_mapping = nullptr;

Copy link
Copy Markdown
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?

Comment thread src/source-maps.h
private:
void CompressMappings();

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

Copy link
Copy Markdown
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?

Comment thread src/source-maps.cc
}

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

Copy link
Copy Markdown
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.

Comment thread src/source-maps.h
// Representation of mappings
struct Segment {
// Field 1
uint32_t generated_col = 0; // Start column in generated code. Remove?

Copy link
Copy Markdown
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?

Comment thread src/source-maps.cc
}

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

Copy link
Copy Markdown
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.

Comment thread src/test-source-maps.cc
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
Copy Markdown
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