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

Fix placement of inserted semicolon when using SystemJS #2529

Merged
merged 2 commits into from Oct 28, 2018

Conversation

kyle1320
Copy link
Contributor

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:
#2527

Description

Fixes #2527.

Currently, semicolons are inserted using appendLeft. But this means that any code inserted after the end of the line will be inserted after the semicolon, which is not what we want.

This fixes the issue by using appendRight instead.

@lukastaegert
Copy link
Member

Hi @kyle1320,

thanks a lot, you are really becoming quite the contributor here 😎
Very nice test, and the solution is definitely valid at the moment. My feeling is, though, that we should fix it in another location, but let me explain first.

The append/prependLeft/Right methods actually work the following way:
Left and Right are important for tree-shaking. If something is added Left, then it is removed when the code to the left is removed. Similarly for Right. append and prepend then determine the insertion order:

  • prepend will put the code in front of everything that has been added to this location before, even other prepended code
  • append will put it after all added (appended or prepended) code

So my worries are about tree-shaking. Using appendRight will associate the semi-colon not with the actual expression statement but with the white-space following it. At the moment this is not an issue because the white-space until the next line-break will be removed together with the statement but this is not guaranteed to be stable in the future.

Instead I would prefer to fix it in AssignmentExpression.ts. Instead of

code.prependRight(this.right.end, `)`);

which is definitely looks wrong following my above explanation, the code should probably be

code.appendLeft(this.right.end, `)`);

@kyle1320 kyle1320 changed the title Fix placement of inserted semicolon Fix placement of inserted semicolon when using SystemJS Oct 26, 2018
@kyle1320
Copy link
Contributor Author

@lukastaegert Thanks for the feedback.

That actually makes a lot of sense! This was my first experience with magic-string, so I was mostly just going off of the documentation. That's why we have reviews I suppose 🙂

I thought I had tried changing the statement in AssignmentExpression.ts before, but after trying it again (and understanding it better now), it works!

I've pushed an update and changed the title of the PR to better reflect the scope of the change.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Looks good, thanks a lot!

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.

SyntaxError with format system (misplaced semicolon)
2 participants