-
Notifications
You must be signed in to change notification settings - Fork 382
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: lwc compiler errors on .jsx/.tsx files #4164
Fix: lwc compiler errors on .jsx/.tsx files #4164
Conversation
Thanks for the contribution! Unfortunately we can't verify the commit author(s): Saurabh Mulay <s***@s***.i***.s***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, sign the Salesforce Inc. Contributor License Agreement and this Pull Request will be revalidated. |
Hi @SaurabhMulay999 thank you for the contribution! Could you please add a test to confirm the fix? The right place to add a test would be in |
Sure, I'll try. |
Hi @nolanlawson , Code:
after debug it was failing saying that. Error: I have checked some online resources it was suggesting to install @babel/preset-react. |
@SaurabhMulay999 It should be fine to just put actual JavaScript in there rather than JSX. We do not need to test transpiling JSX into JavaScript; just that the In a real app setup (e.g. using Rollup), the consumer of LWC would be responsible for ensuring that there are plugins in place to do the transformation. |
Okay. I've added the JS format. I have ran it locally it was successful. Let me know if any modifications are required. |
@SaurabhMulay999 Could you please sign the CLA as described above? |
packages/@lwc/compiler/src/transformers/__tests__/transform-javascript.spec.ts
Outdated
Show resolved
Hide resolved
packages/@lwc/compiler/src/transformers/__tests__/transform-javascript.spec.ts
Outdated
Show resolved
Hide resolved
packages/@lwc/compiler/src/transformers/__tests__/transform-javascript.spec.ts
Outdated
Show resolved
Hide resolved
import { LightningElement } from 'lwc'; | ||
export default class Foo extends LightningElement {} | ||
`; | ||
const fileName = 'app.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const fileName = 'app.js'; | |
const fileName = 'app.jsx'; |
Hey @nolanlawson, |
I think you'll have to redo the commits using the email address associated with your GitHub account. (Or add the email address from your commits to your GitHub account, but the one used here doesn't seem to be a real email address, so I don't think GitHub will let you.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to loop over an array of all the supported file extensions. Something like:
describe('file extension support', () => {
function testFileExtensionSupport(ext: string) {
it(`should support ${ext} file extension`, () => {
const src = `
import { LightningElement } from 'lwc';
export default class Foo extends LightningElement {}
`;
const options = { namespace: 'c', name: 'foo' };
const result = transformSync(src, `foo${ext}`, options);
expect(result.code).toBeDefined();
expect(result.map).toBeDefined();
expect(result.warnings).toBeUndefined();
expect(result.cssScopeTokens).toBeUndefined();
});
}
['.js', '.jsx', '.ts', '.tsx'].forEach(testFileExtensionSupport);
});
@@ -269,3 +269,34 @@ describe('sourcemaps', () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
describe('transformFile function', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('transformFile function', () => { | |
describe('file extension support', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better as you have suggested above to loop over all the extensions.
@@ -269,3 +269,34 @@ describe('sourcemaps', () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
describe('transformFile function', () => { | |||
it('should be tranform Typescript file with ext (.tsx)', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('should be tranform Typescript file with ext (.tsx)', () => { | |
it('should support .tsx file extension', () => { |
expect(result.cssScopeTokens).toBeUndefined(); | ||
}); | ||
|
||
it('should be tranform Javascript file with ext (.jsx)', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('should be tranform Javascript file with ext (.jsx)', () => { | |
it('should support .jsx file extension', () => { |
I think it tried to fetch my official salesforce email. I'll try adding the personal email and then recommit. |
If you use your salesforce email then you don't need to sign the CLA, because it will recognize you as an internal user. |
Yeah, but this is my personal account. I have added the Name as well email in the latest commit. It should have now recognise me as a GitHub user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
The older commits still show the invalid email address. I believe you will need to do an interactive rebase or squash-merge followed by a force-push to fix this. |
Okay. I'll try interactive rebase. |
b60432e
to
84af21a
Compare
fix:lwc compiler errors on jsx tsx files fix: lwc compiler errors on jsx tsx files fix: lwc compiler errors on jsx tsx files fix: lwc compiler errors on jsx tsx files (unit tests) fix: lwc compiler errors on jsx tsx files (unit tests) fix: unit test code formating changes fix: unit test code formating changes fix: unit test code formating changes fix: unit test code formating changes fix: lwc compiler errors on jsx tsx files
84af21a
to
f95a6ef
Compare
Hi @nolanlawson , |
expect(result.cssScopeTokens).toBeUndefined(); | ||
}); | ||
} | ||
['.js', '.jsx', '.ts', '.tsx'].forEach(testFileExtensionSupport); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
/nucleus test |
Details
Fix: LWC compiler errors on .jsx/.tsx files #4122.
(Treating .jsx/.tsx file extensions the same as .js & .ts.)
Does this pull request introduce a breaking change?
Does this pull request introduce an observable change?