@lwc/style-compiler 9.0.4-alpha.2 → 9.1.1-alpha.0

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 CHANGED
@@ -20,7 +20,7 @@ yarn add --dev @lwc/style-compiler
20
20
  ## Usage
21
21
 
22
22
  ```js
23
- const { transform } = require('@lwc/style-compiler');
23
+ import { transform } from '@lwc/style-compiler';
24
24
 
25
25
  const source = `
26
26
  :host {
@@ -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 postCssSelector = require('postcss-selector-parser');
10
+ var postCssSelectorParser = 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 postCssSelector.isPseudoClass(node) && node.value === ':dir';
407
+ return postCssSelectorParser.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 postCssSelector.isPseudoClass(node) && node.value === ':host';
490
+ return postCssSelectorParser.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 (postCssSelector.isCombinator(node)) {
503
+ if (postCssSelectorParser.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 (!postCssSelector.isPseudoElement(node)) {
522
+ if (!postCssSelectorParser.isPseudoElement(node)) {
523
523
  nodeToScope = node;
524
524
  }
525
525
  }
526
- const shadowAttribute = postCssSelector.attribute({
526
+ const shadowAttribute = postCssSelectorParser.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 = postCssSelector.attribute({
566
+ const hostAttribute = postCssSelectorParser.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 = postCssSelector.attribute({
636
+ const nativeAttribute = postCssSelectorParser.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 = postCssSelector.attribute({
641
+ const syntheticAttribute = postCssSelectorParser.attribute({
642
642
  attribute: value === 'ltr' ? DIR_ATTRIBUTE_SYNTHETIC_LTR : DIR_ATTRIBUTE_SYNTHETIC_RTL,
643
643
  value: undefined,
644
644
  raws: {},
@@ -646,9 +646,11 @@ 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 && !postCssSelector.isCombinator(selector.first) && selector.first.value !== ' ';
649
+ const shouldAddDescendantCombinator = selector.first &&
650
+ !postCssSelectorParser.isCombinator(selector.first) &&
651
+ selector.first.value !== ' ';
650
652
  if (shouldAddDescendantCombinator) {
651
- selector.insertBefore(selector.first, postCssSelector.combinator({
653
+ selector.insertBefore(selector.first, postCssSelectorParser.combinator({
652
654
  value: ' ',
653
655
  }));
654
656
  // Add the [dir] attribute in front of the " " combinator, i.e. as an ancestor
@@ -735,7 +737,7 @@ function shouldTransformSelector(rule) {
735
737
  return rule.parent?.type !== 'atrule' || rule.parent.name !== 'keyframes';
736
738
  }
737
739
  function selectorProcessorFactory(transformConfig, ctx) {
738
- return postCssSelector((root) => {
740
+ return postCssSelectorParser((root) => {
739
741
  validateIdSelectors(root, ctx);
740
742
  transformSelector(root, transformConfig, ctx);
741
743
  transformDirPseudoClass(root, ctx);
@@ -843,7 +845,7 @@ class StyleCompilerCtx {
843
845
  * @param config Transformation options
844
846
  * @returns Transformed CSS
845
847
  * @example
846
- * const {transform} = require('@lwc/style-compiler');
848
+ * import { transform } from '@lwc/style-compiler';
847
849
  * const source = `
848
850
  * :host {
849
851
  * opacity: 0.4;
@@ -878,6 +880,7 @@ function transform(src, id, config = {}) {
878
880
  catch (error) {
879
881
  if (errorRecoveryMode && error instanceof postcss.CssSyntaxError) {
880
882
  ctx.errors.push(error);
883
+ // eslint-disable-next-line preserve-caught-error
881
884
  throw AggregateError(ctx.errors);
882
885
  }
883
886
  else {
@@ -891,5 +894,5 @@ function transform(src, id, config = {}) {
891
894
  }
892
895
 
893
896
  exports.transform = transform;
894
- /** version: 9.0.4-alpha.2 */
895
- //# sourceMappingURL=index.cjs.js.map
897
+ /** version: 9.1.1-alpha.0 */
898
+ //# sourceMappingURL=index.cjs.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 postCssSelector, { isPseudoClass, isCombinator, isPseudoElement, attribute, combinator } from 'postcss-selector-parser';
6
+ import postCssSelectorParser 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 isPseudoClass(node) && node.value === ':dir';
403
+ return postCssSelectorParser.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 isPseudoClass(node) && node.value === ':host';
486
+ return postCssSelectorParser.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 (isCombinator(node)) {
499
+ if (postCssSelectorParser.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 (!isPseudoElement(node)) {
518
+ if (!postCssSelectorParser.isPseudoElement(node)) {
519
519
  nodeToScope = node;
520
520
  }
521
521
  }
522
- const shadowAttribute = attribute({
522
+ const shadowAttribute = postCssSelectorParser.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 = attribute({
562
+ const hostAttribute = postCssSelectorParser.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 = attribute({
632
+ const nativeAttribute = postCssSelectorParser.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 = attribute({
637
+ const syntheticAttribute = postCssSelectorParser.attribute({
638
638
  attribute: value === 'ltr' ? DIR_ATTRIBUTE_SYNTHETIC_LTR : DIR_ATTRIBUTE_SYNTHETIC_RTL,
639
639
  value: undefined,
640
640
  raws: {},
@@ -642,9 +642,11 @@ 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 && !isCombinator(selector.first) && selector.first.value !== ' ';
645
+ const shouldAddDescendantCombinator = selector.first &&
646
+ !postCssSelectorParser.isCombinator(selector.first) &&
647
+ selector.first.value !== ' ';
646
648
  if (shouldAddDescendantCombinator) {
647
- selector.insertBefore(selector.first, combinator({
649
+ selector.insertBefore(selector.first, postCssSelectorParser.combinator({
648
650
  value: ' ',
649
651
  }));
650
652
  // Add the [dir] attribute in front of the " " combinator, i.e. as an ancestor
@@ -731,7 +733,7 @@ function shouldTransformSelector(rule) {
731
733
  return rule.parent?.type !== 'atrule' || rule.parent.name !== 'keyframes';
732
734
  }
733
735
  function selectorProcessorFactory(transformConfig, ctx) {
734
- return postCssSelector((root) => {
736
+ return postCssSelectorParser((root) => {
735
737
  validateIdSelectors(root, ctx);
736
738
  transformSelector(root, transformConfig, ctx);
737
739
  transformDirPseudoClass(root, ctx);
@@ -839,7 +841,7 @@ class StyleCompilerCtx {
839
841
  * @param config Transformation options
840
842
  * @returns Transformed CSS
841
843
  * @example
842
- * const {transform} = require('@lwc/style-compiler');
844
+ * import { transform } from '@lwc/style-compiler';
843
845
  * const source = `
844
846
  * :host {
845
847
  * opacity: 0.4;
@@ -874,6 +876,7 @@ function transform(src, id, config = {}) {
874
876
  catch (error) {
875
877
  if (errorRecoveryMode && error instanceof postcss.CssSyntaxError) {
876
878
  ctx.errors.push(error);
879
+ // eslint-disable-next-line preserve-caught-error
877
880
  throw AggregateError(ctx.errors);
878
881
  }
879
882
  else {
@@ -887,5 +890,5 @@ function transform(src, id, config = {}) {
887
890
  }
888
891
 
889
892
  export { transform };
890
- /** version: 9.0.4-alpha.2 */
893
+ /** version: 9.1.1-alpha.0 */
891
894
  //# sourceMappingURL=index.js.map
@@ -24,7 +24,7 @@ export interface Config {
24
24
  * @param config Transformation options
25
25
  * @returns Transformed CSS
26
26
  * @example
27
- * const {transform} = require('@lwc/style-compiler');
27
+ * import { transform } from '@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.2",
7
+ "version": "9.1.1-alpha.0",
8
8
  "description": "Transform style sheet to be consumed by the LWC engine",
9
9
  "keywords": [
10
10
  "lwc"
@@ -19,17 +19,22 @@
19
19
  "url": "https://github.com/salesforce/lwc/issues"
20
20
  },
21
21
  "license": "MIT",
22
+ "type": "module",
22
23
  "publishConfig": {
23
24
  "access": "public"
24
25
  },
26
+ "engines": {
27
+ "node": ">=16.6.0"
28
+ },
25
29
  "volta": {
26
30
  "extends": "../../../package.json"
27
31
  },
28
- "main": "dist/index.cjs.js",
32
+ "main": "dist/index.js",
29
33
  "module": "dist/index.js",
30
34
  "types": "dist/index.d.ts",
31
35
  "files": [
32
36
  "dist/**/*.js",
37
+ "dist/**/*.cjs",
33
38
  "dist/**/*.d.ts"
34
39
  ],
35
40
  "scripts": {
@@ -46,7 +51,7 @@
46
51
  }
47
52
  },
48
53
  "dependencies": {
49
- "@lwc/shared": "9.0.4-alpha.2",
54
+ "@lwc/shared": "9.1.1-alpha.0",
50
55
  "postcss": "~8.5.8",
51
56
  "postcss-selector-parser": "~7.1.1",
52
57
  "postcss-value-parser": "~4.2.0"