@lwc/style-compiler 9.0.4-alpha.0 → 9.0.4-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{index.cjs → index.cjs.js} +15 -18
- package/dist/index.js +14 -17
- package/dist/transform.d.ts +1 -1
- package/package.json +3 -8
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
7
7
|
|
|
8
8
|
var postcss = require('postcss');
|
|
9
9
|
var shared = require('@lwc/shared');
|
|
10
|
-
var
|
|
10
|
+
var postCssSelector = require('postcss-selector-parser');
|
|
11
11
|
var valueParser = require('postcss-value-parser');
|
|
12
12
|
|
|
13
13
|
const PLUGIN_NAME = '@lwc/style-compiler';
|
|
@@ -404,7 +404,7 @@ function process$1(root, result, isScoped, ctx) {
|
|
|
404
404
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
405
405
|
*/
|
|
406
406
|
function isDirPseudoClass(node) {
|
|
407
|
-
return
|
|
407
|
+
return postCssSelector.isPseudoClass(node) && node.value === ':dir';
|
|
408
408
|
}
|
|
409
409
|
|
|
410
410
|
function findNode(container, predicate) {
|
|
@@ -487,7 +487,7 @@ function validate(root, native, ctx) {
|
|
|
487
487
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
488
488
|
*/
|
|
489
489
|
function isHostPseudoClass(node) {
|
|
490
|
-
return
|
|
490
|
+
return postCssSelector.isPseudoClass(node) && node.value === ':host';
|
|
491
491
|
}
|
|
492
492
|
/**
|
|
493
493
|
* Add scoping attributes to all the matching selectors:
|
|
@@ -500,7 +500,7 @@ function scopeSelector(selector) {
|
|
|
500
500
|
// Split the selector per compound selector. Compound selectors are interleaved with combinator nodes.
|
|
501
501
|
// https://drafts.csswg.org/selectors-4/#typedef-complex-selector
|
|
502
502
|
selector.each((node) => {
|
|
503
|
-
if (
|
|
503
|
+
if (postCssSelector.isCombinator(node)) {
|
|
504
504
|
compoundSelectors.push([]);
|
|
505
505
|
}
|
|
506
506
|
else {
|
|
@@ -519,11 +519,11 @@ function scopeSelector(selector) {
|
|
|
519
519
|
let nodeToScope;
|
|
520
520
|
// In each compound selector we need to locate the last selector to scope.
|
|
521
521
|
for (const node of compoundSelector) {
|
|
522
|
-
if (!
|
|
522
|
+
if (!postCssSelector.isPseudoElement(node)) {
|
|
523
523
|
nodeToScope = node;
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
|
-
const shadowAttribute =
|
|
526
|
+
const shadowAttribute = postCssSelector.attribute({
|
|
527
527
|
attribute: SHADOW_ATTRIBUTE,
|
|
528
528
|
value: undefined,
|
|
529
529
|
raws: {},
|
|
@@ -563,7 +563,7 @@ function transformHost(selector) {
|
|
|
563
563
|
// Store the original location of the :host in the selector
|
|
564
564
|
const hostIndex = selector.index(hostNode);
|
|
565
565
|
// Swap the :host pseudo-class with the host scoping token
|
|
566
|
-
const hostAttribute =
|
|
566
|
+
const hostAttribute = postCssSelector.attribute({
|
|
567
567
|
attribute: HOST_ATTRIBUTE,
|
|
568
568
|
value: undefined,
|
|
569
569
|
raws: {},
|
|
@@ -633,12 +633,12 @@ function transformDirPseudoClass (root, ctx) {
|
|
|
633
633
|
// I.e. we need to use a descendant selector (' ' combinator) relying on a `dir`
|
|
634
634
|
// attribute added to the host element. So we need two placeholders:
|
|
635
635
|
// `<synthetic_placeholder> .foo<native_placeholder>:not(.bar)`
|
|
636
|
-
const nativeAttribute =
|
|
636
|
+
const nativeAttribute = postCssSelector.attribute({
|
|
637
637
|
attribute: value === 'ltr' ? DIR_ATTRIBUTE_NATIVE_LTR : DIR_ATTRIBUTE_NATIVE_RTL,
|
|
638
638
|
value: undefined,
|
|
639
639
|
raws: {},
|
|
640
640
|
});
|
|
641
|
-
const syntheticAttribute =
|
|
641
|
+
const syntheticAttribute = postCssSelector.attribute({
|
|
642
642
|
attribute: value === 'ltr' ? DIR_ATTRIBUTE_SYNTHETIC_LTR : DIR_ATTRIBUTE_SYNTHETIC_RTL,
|
|
643
643
|
value: undefined,
|
|
644
644
|
raws: {},
|
|
@@ -646,11 +646,9 @@ function transformDirPseudoClass (root, ctx) {
|
|
|
646
646
|
node.replaceWith(nativeAttribute);
|
|
647
647
|
// If the selector is not empty and if the first node in the selector is not already a
|
|
648
648
|
// " " combinator, we need to use the descendant selector format
|
|
649
|
-
const shouldAddDescendantCombinator = selector.first &&
|
|
650
|
-
!postCssSelectorParser.isCombinator(selector.first) &&
|
|
651
|
-
selector.first.value !== ' ';
|
|
649
|
+
const shouldAddDescendantCombinator = selector.first && !postCssSelector.isCombinator(selector.first) && selector.first.value !== ' ';
|
|
652
650
|
if (shouldAddDescendantCombinator) {
|
|
653
|
-
selector.insertBefore(selector.first,
|
|
651
|
+
selector.insertBefore(selector.first, postCssSelector.combinator({
|
|
654
652
|
value: ' ',
|
|
655
653
|
}));
|
|
656
654
|
// Add the [dir] attribute in front of the " " combinator, i.e. as an ancestor
|
|
@@ -737,7 +735,7 @@ function shouldTransformSelector(rule) {
|
|
|
737
735
|
return rule.parent?.type !== 'atrule' || rule.parent.name !== 'keyframes';
|
|
738
736
|
}
|
|
739
737
|
function selectorProcessorFactory(transformConfig, ctx) {
|
|
740
|
-
return
|
|
738
|
+
return postCssSelector((root) => {
|
|
741
739
|
validateIdSelectors(root, ctx);
|
|
742
740
|
transformSelector(root, transformConfig, ctx);
|
|
743
741
|
transformDirPseudoClass(root, ctx);
|
|
@@ -845,7 +843,7 @@ class StyleCompilerCtx {
|
|
|
845
843
|
* @param config Transformation options
|
|
846
844
|
* @returns Transformed CSS
|
|
847
845
|
* @example
|
|
848
|
-
*
|
|
846
|
+
* const {transform} = require('@lwc/style-compiler');
|
|
849
847
|
* const source = `
|
|
850
848
|
* :host {
|
|
851
849
|
* opacity: 0.4;
|
|
@@ -880,7 +878,6 @@ function transform(src, id, config = {}) {
|
|
|
880
878
|
catch (error) {
|
|
881
879
|
if (errorRecoveryMode && error instanceof postcss.CssSyntaxError) {
|
|
882
880
|
ctx.errors.push(error);
|
|
883
|
-
// eslint-disable-next-line preserve-caught-error
|
|
884
881
|
throw AggregateError(ctx.errors);
|
|
885
882
|
}
|
|
886
883
|
else {
|
|
@@ -894,5 +891,5 @@ function transform(src, id, config = {}) {
|
|
|
894
891
|
}
|
|
895
892
|
|
|
896
893
|
exports.transform = transform;
|
|
897
|
-
/** version: 9.0.4-alpha.
|
|
898
|
-
//# sourceMappingURL=index.cjs.map
|
|
894
|
+
/** version: 9.0.4-alpha.2 */
|
|
895
|
+
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import postcss, { CssSyntaxError } from 'postcss';
|
|
5
5
|
import { LWC_VERSION_COMMENT, KEY__SCOPED_CSS, KEY__NATIVE_ONLY_CSS, getAPIVersionFromNumber } from '@lwc/shared';
|
|
6
|
-
import
|
|
6
|
+
import postCssSelector, { isPseudoClass, isCombinator, isPseudoElement, attribute, combinator } from 'postcss-selector-parser';
|
|
7
7
|
import valueParser from 'postcss-value-parser';
|
|
8
8
|
|
|
9
9
|
const PLUGIN_NAME = '@lwc/style-compiler';
|
|
@@ -400,7 +400,7 @@ function process$1(root, result, isScoped, ctx) {
|
|
|
400
400
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
401
401
|
*/
|
|
402
402
|
function isDirPseudoClass(node) {
|
|
403
|
-
return
|
|
403
|
+
return isPseudoClass(node) && node.value === ':dir';
|
|
404
404
|
}
|
|
405
405
|
|
|
406
406
|
function findNode(container, predicate) {
|
|
@@ -483,7 +483,7 @@ function validate(root, native, ctx) {
|
|
|
483
483
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
484
484
|
*/
|
|
485
485
|
function isHostPseudoClass(node) {
|
|
486
|
-
return
|
|
486
|
+
return isPseudoClass(node) && node.value === ':host';
|
|
487
487
|
}
|
|
488
488
|
/**
|
|
489
489
|
* Add scoping attributes to all the matching selectors:
|
|
@@ -496,7 +496,7 @@ function scopeSelector(selector) {
|
|
|
496
496
|
// Split the selector per compound selector. Compound selectors are interleaved with combinator nodes.
|
|
497
497
|
// https://drafts.csswg.org/selectors-4/#typedef-complex-selector
|
|
498
498
|
selector.each((node) => {
|
|
499
|
-
if (
|
|
499
|
+
if (isCombinator(node)) {
|
|
500
500
|
compoundSelectors.push([]);
|
|
501
501
|
}
|
|
502
502
|
else {
|
|
@@ -515,11 +515,11 @@ function scopeSelector(selector) {
|
|
|
515
515
|
let nodeToScope;
|
|
516
516
|
// In each compound selector we need to locate the last selector to scope.
|
|
517
517
|
for (const node of compoundSelector) {
|
|
518
|
-
if (!
|
|
518
|
+
if (!isPseudoElement(node)) {
|
|
519
519
|
nodeToScope = node;
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
|
-
const shadowAttribute =
|
|
522
|
+
const shadowAttribute = attribute({
|
|
523
523
|
attribute: SHADOW_ATTRIBUTE,
|
|
524
524
|
value: undefined,
|
|
525
525
|
raws: {},
|
|
@@ -559,7 +559,7 @@ function transformHost(selector) {
|
|
|
559
559
|
// Store the original location of the :host in the selector
|
|
560
560
|
const hostIndex = selector.index(hostNode);
|
|
561
561
|
// Swap the :host pseudo-class with the host scoping token
|
|
562
|
-
const hostAttribute =
|
|
562
|
+
const hostAttribute = attribute({
|
|
563
563
|
attribute: HOST_ATTRIBUTE,
|
|
564
564
|
value: undefined,
|
|
565
565
|
raws: {},
|
|
@@ -629,12 +629,12 @@ function transformDirPseudoClass (root, ctx) {
|
|
|
629
629
|
// I.e. we need to use a descendant selector (' ' combinator) relying on a `dir`
|
|
630
630
|
// attribute added to the host element. So we need two placeholders:
|
|
631
631
|
// `<synthetic_placeholder> .foo<native_placeholder>:not(.bar)`
|
|
632
|
-
const nativeAttribute =
|
|
632
|
+
const nativeAttribute = attribute({
|
|
633
633
|
attribute: value === 'ltr' ? DIR_ATTRIBUTE_NATIVE_LTR : DIR_ATTRIBUTE_NATIVE_RTL,
|
|
634
634
|
value: undefined,
|
|
635
635
|
raws: {},
|
|
636
636
|
});
|
|
637
|
-
const syntheticAttribute =
|
|
637
|
+
const syntheticAttribute = attribute({
|
|
638
638
|
attribute: value === 'ltr' ? DIR_ATTRIBUTE_SYNTHETIC_LTR : DIR_ATTRIBUTE_SYNTHETIC_RTL,
|
|
639
639
|
value: undefined,
|
|
640
640
|
raws: {},
|
|
@@ -642,11 +642,9 @@ function transformDirPseudoClass (root, ctx) {
|
|
|
642
642
|
node.replaceWith(nativeAttribute);
|
|
643
643
|
// If the selector is not empty and if the first node in the selector is not already a
|
|
644
644
|
// " " combinator, we need to use the descendant selector format
|
|
645
|
-
const shouldAddDescendantCombinator = selector.first &&
|
|
646
|
-
!postCssSelectorParser.isCombinator(selector.first) &&
|
|
647
|
-
selector.first.value !== ' ';
|
|
645
|
+
const shouldAddDescendantCombinator = selector.first && !isCombinator(selector.first) && selector.first.value !== ' ';
|
|
648
646
|
if (shouldAddDescendantCombinator) {
|
|
649
|
-
selector.insertBefore(selector.first,
|
|
647
|
+
selector.insertBefore(selector.first, combinator({
|
|
650
648
|
value: ' ',
|
|
651
649
|
}));
|
|
652
650
|
// Add the [dir] attribute in front of the " " combinator, i.e. as an ancestor
|
|
@@ -733,7 +731,7 @@ function shouldTransformSelector(rule) {
|
|
|
733
731
|
return rule.parent?.type !== 'atrule' || rule.parent.name !== 'keyframes';
|
|
734
732
|
}
|
|
735
733
|
function selectorProcessorFactory(transformConfig, ctx) {
|
|
736
|
-
return
|
|
734
|
+
return postCssSelector((root) => {
|
|
737
735
|
validateIdSelectors(root, ctx);
|
|
738
736
|
transformSelector(root, transformConfig, ctx);
|
|
739
737
|
transformDirPseudoClass(root, ctx);
|
|
@@ -841,7 +839,7 @@ class StyleCompilerCtx {
|
|
|
841
839
|
* @param config Transformation options
|
|
842
840
|
* @returns Transformed CSS
|
|
843
841
|
* @example
|
|
844
|
-
*
|
|
842
|
+
* const {transform} = require('@lwc/style-compiler');
|
|
845
843
|
* const source = `
|
|
846
844
|
* :host {
|
|
847
845
|
* opacity: 0.4;
|
|
@@ -876,7 +874,6 @@ function transform(src, id, config = {}) {
|
|
|
876
874
|
catch (error) {
|
|
877
875
|
if (errorRecoveryMode && error instanceof postcss.CssSyntaxError) {
|
|
878
876
|
ctx.errors.push(error);
|
|
879
|
-
// eslint-disable-next-line preserve-caught-error
|
|
880
877
|
throw AggregateError(ctx.errors);
|
|
881
878
|
}
|
|
882
879
|
else {
|
|
@@ -890,5 +887,5 @@ function transform(src, id, config = {}) {
|
|
|
890
887
|
}
|
|
891
888
|
|
|
892
889
|
export { transform };
|
|
893
|
-
/** version: 9.0.4-alpha.
|
|
890
|
+
/** version: 9.0.4-alpha.2 */
|
|
894
891
|
//# sourceMappingURL=index.js.map
|
package/dist/transform.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export interface Config {
|
|
|
24
24
|
* @param config Transformation options
|
|
25
25
|
* @returns Transformed CSS
|
|
26
26
|
* @example
|
|
27
|
-
*
|
|
27
|
+
* const {transform} = require('@lwc/style-compiler');
|
|
28
28
|
* const source = `
|
|
29
29
|
* :host {
|
|
30
30
|
* opacity: 0.4;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"You can safely modify dependencies, devDependencies, keywords, etc., but other props will be overwritten."
|
|
5
5
|
],
|
|
6
6
|
"name": "@lwc/style-compiler",
|
|
7
|
-
"version": "9.0.4-alpha.
|
|
7
|
+
"version": "9.0.4-alpha.2",
|
|
8
8
|
"description": "Transform style sheet to be consumed by the LWC engine",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"lwc"
|
|
@@ -19,22 +19,17 @@
|
|
|
19
19
|
"url": "https://github.com/salesforce/lwc/issues"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
|
-
"type": "module",
|
|
23
22
|
"publishConfig": {
|
|
24
23
|
"access": "public"
|
|
25
24
|
},
|
|
26
|
-
"engines": {
|
|
27
|
-
"node": ">=16.6.0"
|
|
28
|
-
},
|
|
29
25
|
"volta": {
|
|
30
26
|
"extends": "../../../package.json"
|
|
31
27
|
},
|
|
32
|
-
"main": "dist/index.js",
|
|
28
|
+
"main": "dist/index.cjs.js",
|
|
33
29
|
"module": "dist/index.js",
|
|
34
30
|
"types": "dist/index.d.ts",
|
|
35
31
|
"files": [
|
|
36
32
|
"dist/**/*.js",
|
|
37
|
-
"dist/**/*.cjs",
|
|
38
33
|
"dist/**/*.d.ts"
|
|
39
34
|
],
|
|
40
35
|
"scripts": {
|
|
@@ -51,7 +46,7 @@
|
|
|
51
46
|
}
|
|
52
47
|
},
|
|
53
48
|
"dependencies": {
|
|
54
|
-
"@lwc/shared": "9.0.4-alpha.
|
|
49
|
+
"@lwc/shared": "9.0.4-alpha.2",
|
|
55
50
|
"postcss": "~8.5.8",
|
|
56
51
|
"postcss-selector-parser": "~7.1.1",
|
|
57
52
|
"postcss-value-parser": "~4.2.0"
|