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: support multiple imports of one module with multiple lines #30314

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

wenfw
Copy link

@wenfw wenfw commented Sep 29, 2024

The . in RegExp matches all characters except line terminators, so the following won't match:

import {
  a,
  b,
  c,
} from 'x';

Changing it to [^;'"] allows it to match all characters, including \n, except for ;'", which resolves the issue.

Using the current regular expression /(?<=^|\s)import (.+?) from ['"](.*?)['"]/g will cause the new test cases to fail.

Additional details

Steps to test

How has the user experience changed?

PR Tasks

@CLAassistant
Copy link

CLAassistant commented Sep 29, 2024

CLA assistant check
All committers have signed the CLA.

@cypress-app-bot
Copy link
Collaborator

@jennifer-shehane
Copy link
Member

@wenfw Could you write a test for this change?

e.g.
```
import {
  a,
  b,
  c,
} from 'x';
```
@wenfw
Copy link
Author

wenfw commented Oct 10, 2024

@wenfw Could you write a test for this change?

@jennifer-shehane Test cases have been updated. Thanks.

Copy link
Contributor

@AtofStryker AtofStryker left a comment

Choose a reason for hiding this comment

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

Hi @wenfw. Thank you for the contribution! At first glance I am not sure exactly what this is solving. Can you add a more descriptive PR description to describe the current problem and how your solution addresses that problem?

@wenfw
Copy link
Author

wenfw commented Oct 12, 2024

@AtofStryker The . in RegExp matches all characters except line terminators, so the following won't match:

import {
  a,
  b,
  c,
} from 'x';

Changing it to [^;'"] allows it to match all characters, including \n, except for ;'", which resolves the issue.

Using the current regular expression /(?<=^|\s)import (.+?) from ['"](.*?)['"]/g will cause the new test cases to fail.

@AtofStryker AtofStryker self-requested a review October 15, 2024 15:11
Copy link

@allexiusw allexiusw left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -38,7 +55,7 @@ describe('supports every combination of import syntax in a single file', () => {
})

it('Import { export1 } from "./kitchenSink"', () => {
expect(export1).to.deep.eq(export1)
expect(export1).to.deep.eq('export1')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(export1).to.deep.eq('export1')
expect(export1).to.eq('export1')

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.

6 participants