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

sourceLocations is broken when tags are implied #80

Merged
merged 10 commits into from
Aug 30, 2021

Conversation

thewilkybarkid
Copy link
Contributor

This is deliberately left as a draft as it should demonstrate a bug as a result of fb55/htmlparser2#896, which causes parcel-bundler/parcel#6672.

I don't think it's possible to work around it here, but there will probably need to be code changes when the htmlparser2 bug is resolved.

@thewilkybarkid
Copy link
Contributor Author

htmlparser2 has had a code change that looks to correct the issue there (fb55/htmlparser2#910), but the problem is still seen here (as the same indices are seen twice).

src/index.ts Outdated Show resolved Hide resolved
@thewilkybarkid
Copy link
Contributor Author

Mostly works, but the start of the </p> paragraph seems to be calculated as the / rather than the <.

@thewilkybarkid
Copy link
Contributor Author

Thanks, @fb55; unfortunately that change doesn't seem to make a difference...

@fb55
Copy link

fb55 commented Aug 23, 2021

unfortunately that change doesn't seem to make a difference

The start of a closing tag is now set to the < instead of the /. Do you have an example where it doesn't work?

@thewilkybarkid
Copy link
Contributor Author

thewilkybarkid commented Aug 23, 2021

Unfortunately, CI isn't running on this PR yet, but the test fails on the implied start tag for the </p>:

      {
        location: {
          end: Object { … },
          start: {
  -         column: 19,
  +         column: 18,
            line: 2,
          },
        },
        tag: 'p',
      },

with and without the change. (18 being the expected value.)

Edit: Debugging it, the startIndex is 32 and the endIndex is 34 on the implied start tag. The former should be 31?

@fb55
Copy link

fb55 commented Aug 23, 2021

Good find! Turns out the index was overwritten for implied opening tags. I've opened fb55/htmlparser2#917 with a fix.

@thewilkybarkid
Copy link
Contributor Author

@fb55 Thanks, the test's now passing. 😃

@thewilkybarkid
Copy link
Contributor Author

I'll mark this as ready when you're able to do a new patch release @fb55.

@fb55
Copy link

fb55 commented Aug 27, 2021

I just published [email protected]. With this version you'll be able to check an isImplied flag on onopentag/onclosetag events, which should make this PR much simpler: fb55/htmlparser2#930

@thewilkybarkid
Copy link
Contributor Author

That's great, thanks!

@thewilkybarkid thewilkybarkid marked this pull request as ready for review August 28, 2021 18:53
@thewilkybarkid
Copy link
Contributor Author

Marking this as ready as there's a stable htmlparser release that's working.

Had a quick go at using the isImplied options and it doesn't seem to work as expected, the </b> in the test seems to flagged as implied, when it's not. /cc @fb55

fb55 added a commit to fb55/htmlparser2 that referenced this pull request Aug 29, 2021
@fb55
Copy link

fb55 commented Aug 29, 2021

Had a quick go at using the isImplied options and it doesn't seem to work as expected

Thanks for flagging! I published 7.1.1 with a fix for this, as well as for text events having wrong indices.

@thewilkybarkid
Copy link
Contributor Author

Thanks, @fb55. It's now passing, and it is definitely simpler. ✨

@Scrum Scrum merged commit 1790a35 into posthtml:master Aug 30, 2021
@Scrum
Copy link
Member

Scrum commented Aug 30, 2021

@thewilkybarkid @fb55 Thanks guys, released in version 0.10.1

@thewilkybarkid thewilkybarkid deleted the source-indices branch August 30, 2021 07:38
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.

3 participants