-
Notifications
You must be signed in to change notification settings - Fork 400
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
feat(jest-transformer): Add babel transform for new scoped imports #463
Conversation
Benchmark resultsBase commit: |
import { default as label } from '@salesforce/apex/FooController.fooMethod'; | ||
`, undefined, 'Invalid import from @salesforce/apex/FooController.fooMethod'); | ||
|
||
test('throws error if renamed multipel default imports', ` |
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.
s/multipel/multiple/
} catch (e) { | ||
objectApiName = { | ||
objectApiName: "Opportunity", | ||
fieldApiName: undefined |
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.
We shouldn't provision fieldApiName
on an object import
} | ||
`); | ||
|
||
const schemaObjectTemplate = babelTemplate(` |
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.
We need two templates:
- schemaObject that returns
{objectApiName}
- schemaField that returns
{objectApiName, fieldApiName}
[1] is used for import x from @salesforce/schema/<word>
[2] is used for import x from @salesforce/schema/<word>[.<word>]+
const resourcePath = importSource.substring(importIdentifier.length + 1); | ||
const idx = resourcePath.indexOf('.'); | ||
|
||
if (idx === -1) { |
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.
This logic needs tweaking per comment above. It's also the place you can pivot the logic.
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
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.
One nitpick on variable names otherwise is good to merge
@@ -18,7 +18,16 @@ const resolvedPromiseTemplate = babelTemplate(` | |||
} | |||
`); | |||
|
|||
const schemaObjectTemplate = babelTemplate(` | |||
const schemaSObjectTemplate = babelTemplate(` |
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.
Can we call these schemaObjectTemplate
and schemaObjectAndFieldTemplate
? In the future there will be other templates (eg field sets).
Benchmark resultsBase commit: lwc-engine-benchmark
|
Details
As part of the work to fold scoped module imports all under
@salesforce
, we need to update the Jest transformer to handle the new imports in a similar way that@label
is handled so tests do not error on load. The transformation for the new imports follows the same pattern as@label
, but may provide a different fallback value depending on the import type.Does this PR introduce a breaking change?