-
Notifications
You must be signed in to change notification settings - Fork 31
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(serializer): replace LWC scope tokens (BREAKING CHANGE) #185
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8c9e6e6
fix(serializer): replace LWC scope tokens (BREAKING CHANGE)
nolanlawson b80a978
fix: use lwc:scope-token
nolanlawson d692dec
Revert "fix: use lwc:scope-token"
nolanlawson 7482ddc
fix: use lwc-xxxxxx
nolanlawson 848fbcd
Revert "fix: use lwc-xxxxxx"
nolanlawson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/@lwc/jest-serializer/src/clean-element-classes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
const { isKnownScopeToken } = require('@lwc/jest-shared'); | ||
|
||
function cleanElementClasses(elm) { | ||
for (const name of [...elm.classList]) { | ||
if (isKnownScopeToken(name)) { | ||
elm.classList.replace(name, '__lwc_scope_token__'); | ||
} | ||
} | ||
} | ||
|
||
module.exports = cleanElementClasses; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
const { getKnownScopeTokens } = require('@lwc/jest-shared'); | ||
|
||
function cleanStyleElement(elm) { | ||
// attributes in the HTML namespace are case-insensitive, so the regex must be case-insensitive | ||
const regex = new RegExp(getKnownScopeTokens().join('|'), 'gi'); | ||
elm.textContent = elm.textContent.replace(regex, '__lwc_scope_token__'); | ||
} | ||
|
||
module.exports = cleanStyleElement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
test/src/modules/serializer/styledMultiple/__tests__/styledMultiple.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import { createElement } from 'lwc'; | ||
import StyledMultiple from '../styledMultiple'; | ||
|
||
it('serializes component with HTML - styled in shadow DOM - multiple attrs/classes/styles', () => { | ||
const elm = createElement('serializer-component', { is: StyledMultiple }); | ||
document.body.appendChild(elm); | ||
|
||
if (global['lwc-jest'].nativeShadow) { | ||
expect(elm).toMatchInlineSnapshot(` | ||
<serializer-component | ||
class="__lwc_scope_token__" | ||
> | ||
#shadow-root(open) | ||
<style | ||
type="text/css" | ||
> | ||
:host {opacity: 0.5;}h1 {color: red;}.foo {background: azure;} | ||
</style> | ||
<style | ||
type="text/css" | ||
> | ||
:host {color: goldenrod;}h1.__lwc_scope_token__ {background: blue;}.foo.__lwc_scope_token__ {opacity: 0.7;} | ||
</style> | ||
<h1 | ||
class="foo bar __lwc_scope_token__" | ||
data-bar="bar" | ||
data-foo="foo" | ||
> | ||
I am an LWC component with multiple classes, attributes, and styles | ||
</h1> | ||
</serializer-component> | ||
`); | ||
} else { | ||
expect(elm).toMatchInlineSnapshot(` | ||
<serializer-component | ||
__lwc_scope_token__="" | ||
class="__lwc_scope_token__" | ||
> | ||
#shadow-root(open) | ||
<h1 | ||
__lwc_scope_token__="" | ||
class="foo bar __lwc_scope_token__" | ||
data-bar="bar" | ||
data-foo="foo" | ||
> | ||
I am an LWC component with multiple classes, attributes, and styles | ||
</h1> | ||
</serializer-component> | ||
`); | ||
} | ||
}); |
11 changes: 11 additions & 0 deletions
11
test/src/modules/serializer/styledMultiple/styledMultiple.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
:host { | ||
opacity: 0.5; | ||
} | ||
|
||
h1 { | ||
color: red; | ||
} | ||
|
||
.foo { | ||
background: azure; | ||
} |
7 changes: 7 additions & 0 deletions
7
test/src/modules/serializer/styledMultiple/styledMultiple.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<template> | ||
<h1 | ||
class="foo bar" | ||
data-foo="foo" | ||
data-bar="bar" | ||
>I am an LWC component with multiple classes, attributes, and styles</h1> | ||
</template> |
11 changes: 11 additions & 0 deletions
11
test/src/modules/serializer/styledMultiple/styledMultiple.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import { LightningElement } from 'lwc'; | ||
|
||
export default class extends LightningElement { | ||
} |
11 changes: 11 additions & 0 deletions
11
test/src/modules/serializer/styledMultiple/styledMultiple.scoped.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
:host { | ||
color: goldenrod; | ||
} | ||
|
||
h1 { | ||
background: blue; | ||
} | ||
|
||
.foo { | ||
opacity: 0.7; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@lwc/compiler
v2.48.0 added thecssScopeTokens
return value, which we need. We might as well bump every other LWC peer dep as well, since folks shouldn't be mixing-and-matching different versions of LWC packages.