@wyw-in-js/processor-utils 1.1.0 → 2.0.0-alpha.1

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.
Files changed (95) hide show
  1. package/esm/BaseProcessor.js +48 -76
  2. package/esm/BaseProcessor.js.map +1 -1
  3. package/esm/TaggedTemplateProcessor.js +32 -41
  4. package/esm/TaggedTemplateProcessor.js.map +1 -1
  5. package/esm/ast.js +72 -0
  6. package/esm/ast.js.map +1 -0
  7. package/esm/diagnostics.js +4 -4
  8. package/esm/diagnostics.js.map +1 -1
  9. package/esm/index.js +9 -8
  10. package/esm/index.js.map +1 -1
  11. package/esm/static.js +2 -0
  12. package/esm/static.js.map +1 -0
  13. package/esm/types.js +1 -1
  14. package/esm/types.js.map +1 -1
  15. package/esm/utils/buildSlug.js +2 -2
  16. package/esm/utils/buildSlug.js.map +1 -1
  17. package/esm/utils/getClassNameAndSlug.js +38 -41
  18. package/esm/utils/getClassNameAndSlug.js.map +1 -1
  19. package/esm/utils/getVariableName.js +7 -10
  20. package/esm/utils/getVariableName.js.map +1 -1
  21. package/esm/utils/stripLines.js +9 -11
  22. package/esm/utils/stripLines.js.map +1 -1
  23. package/esm/utils/templateProcessor.js +98 -118
  24. package/esm/utils/templateProcessor.js.map +1 -1
  25. package/esm/utils/throwIfInvalid.js +11 -12
  26. package/esm/utils/throwIfInvalid.js.map +1 -1
  27. package/esm/utils/toCSS.js +34 -43
  28. package/esm/utils/toCSS.js.map +1 -1
  29. package/esm/utils/toValidCSSIdentifier.js +2 -2
  30. package/esm/utils/toValidCSSIdentifier.js.map +1 -1
  31. package/esm/utils/types.js +1 -1
  32. package/esm/utils/types.js.map +1 -1
  33. package/esm/utils/units.js +79 -61
  34. package/esm/utils/units.js.map +1 -1
  35. package/esm/utils/validateParams.js +29 -39
  36. package/esm/utils/validateParams.js.map +1 -1
  37. package/package.json +15 -15
  38. package/types/BaseProcessor.d.ts +9 -12
  39. package/types/BaseProcessor.js +13 -22
  40. package/types/TaggedTemplateProcessor.d.ts +1 -1
  41. package/types/TaggedTemplateProcessor.js +9 -16
  42. package/types/ast.d.ts +95 -0
  43. package/types/ast.js +80 -0
  44. package/types/diagnostics.js +3 -8
  45. package/types/index.d.ts +4 -1
  46. package/types/index.js +8 -33
  47. package/types/static.d.ts +63 -0
  48. package/types/static.js +1 -0
  49. package/types/types.d.ts +1 -1
  50. package/types/types.js +1 -2
  51. package/types/utils/buildSlug.js +1 -4
  52. package/types/utils/getClassNameAndSlug.js +15 -18
  53. package/types/utils/getVariableName.js +1 -4
  54. package/types/utils/stripLines.js +1 -4
  55. package/types/utils/templateProcessor.d.ts +1 -1
  56. package/types/utils/templateProcessor.js +16 -55
  57. package/types/utils/throwIfInvalid.js +1 -3
  58. package/types/utils/toCSS.js +8 -13
  59. package/types/utils/toValidCSSIdentifier.js +1 -4
  60. package/types/utils/types.d.ts +4 -2
  61. package/types/utils/types.js +1 -2
  62. package/types/utils/units.js +2 -5
  63. package/types/utils/validateParams.js +2 -6
  64. package/lib/BaseProcessor.js +0 -87
  65. package/lib/BaseProcessor.js.map +0 -1
  66. package/lib/TaggedTemplateProcessor.js +0 -51
  67. package/lib/TaggedTemplateProcessor.js.map +0 -1
  68. package/lib/diagnostics.js +0 -12
  69. package/lib/diagnostics.js.map +0 -1
  70. package/lib/index.js +0 -89
  71. package/lib/index.js.map +0 -1
  72. package/lib/types.js +0 -2
  73. package/lib/types.js.map +0 -1
  74. package/lib/utils/buildSlug.js +0 -12
  75. package/lib/utils/buildSlug.js.map +0 -1
  76. package/lib/utils/getClassNameAndSlug.js +0 -50
  77. package/lib/utils/getClassNameAndSlug.js.map +0 -1
  78. package/lib/utils/getVariableName.js +0 -18
  79. package/lib/utils/getVariableName.js.map +0 -1
  80. package/lib/utils/stripLines.js +0 -22
  81. package/lib/utils/stripLines.js.map +0 -1
  82. package/lib/utils/templateProcessor.js +0 -129
  83. package/lib/utils/templateProcessor.js.map +0 -1
  84. package/lib/utils/throwIfInvalid.js +0 -35
  85. package/lib/utils/throwIfInvalid.js.map +0 -1
  86. package/lib/utils/toCSS.js +0 -58
  87. package/lib/utils/toCSS.js.map +0 -1
  88. package/lib/utils/toValidCSSIdentifier.js +0 -10
  89. package/lib/utils/toValidCSSIdentifier.js.map +0 -1
  90. package/lib/utils/types.js +0 -2
  91. package/lib/utils/types.js.map +0 -1
  92. package/lib/utils/units.js +0 -71
  93. package/lib/utils/units.js.map +0 -1
  94. package/lib/utils/validateParams.js +0 -54
  95. package/lib/utils/validateParams.js.map +0 -1
@@ -1,87 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BaseProcessor = void 0;
7
- var _generator = _interopRequireDefault(require("@babel/generator"));
8
- var _shared = require("@wyw-in-js/shared");
9
- var _diagnostics = require("./diagnostics");
10
- var _getClassNameAndSlug = _interopRequireDefault(require("./utils/getClassNameAndSlug"));
11
- var _toCSS = require("./utils/toCSS");
12
- var _validateParams = require("./utils/validateParams");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- /* eslint-disable class-methods-use-this */
15
-
16
- class BaseProcessor {
17
- static SKIP = Symbol('skip');
18
- artifacts = [];
19
- dependencies = [];
20
- interpolations = [];
21
- constructor(params, tagSource, astService, location, replacer, displayName, isReferenced, idx, options, context) {
22
- this.tagSource = tagSource;
23
- this.astService = astService;
24
- this.location = location;
25
- this.replacer = replacer;
26
- this.displayName = displayName;
27
- this.isReferenced = isReferenced;
28
- this.idx = idx;
29
- this.options = options;
30
- this.context = context;
31
- (0, _validateParams.validateParams)(params, ['callee'], 'Unknown error: a callee param is not specified');
32
- const {
33
- className,
34
- slug
35
- } = (0, _getClassNameAndSlug.default)(this.displayName, this.idx, this.options, this.context);
36
- this.className = className;
37
- this.slug = slug;
38
- [[, this.callee]] = params;
39
- }
40
-
41
- /**
42
- * A replacement for tag referenced in a template literal.
43
- */
44
-
45
- /**
46
- * A replacement for the tag in evaluation time.
47
- * For example, `css` tag will be replaced with its className,
48
- * whereas `styled` tag will be replaced with an object with metadata.
49
- */
50
-
51
- addDiagnostic(diagnostic) {
52
- var _ref, _diagnostic$end, _this$location, _ref2, _diagnostic$start, _this$location2;
53
- this.artifacts.push((0, _diagnostics.createProcessorDiagnosticArtifact)({
54
- ...diagnostic,
55
- end: (_ref = (_diagnostic$end = diagnostic.end) !== null && _diagnostic$end !== void 0 ? _diagnostic$end : (_this$location = this.location) === null || _this$location === void 0 ? void 0 : _this$location.end) !== null && _ref !== void 0 ? _ref : null,
56
- start: (_ref2 = (_diagnostic$start = diagnostic.start) !== null && _diagnostic$start !== void 0 ? _diagnostic$start : (_this$location2 = this.location) === null || _this$location2 === void 0 ? void 0 : _this$location2.start) !== null && _ref2 !== void 0 ? _ref2 : null
57
- }));
58
- }
59
- isValidValue(value) {
60
- return typeof value === 'function' || (0, _toCSS.isCSSable)(value) || (0, _shared.hasEvalMeta)(value);
61
- }
62
- toString() {
63
- return this.tagSourceCode();
64
- }
65
- tagSourceCode() {
66
- if (this.callee.type === 'Identifier') {
67
- return this.callee.name;
68
- }
69
- return (0, _generator.default)(this.callee).code;
70
- }
71
-
72
- /**
73
- * Perform a replacement for the tag in evaluation time.
74
- * For example, `css` tag will be replaced with its className,
75
- * whereas `styled` tag will be replaced with an object with metadata.
76
- */
77
-
78
- /**
79
- * Perform a replacement for the tag with its runtime version.
80
- * For example, `css` tag will be replaced with its className,
81
- * whereas `styled` tag will be replaced with a component.
82
- * If some parts require evaluated data for render,
83
- * they will be replaced with placeholders.
84
- */
85
- }
86
- exports.BaseProcessor = BaseProcessor;
87
- //# sourceMappingURL=BaseProcessor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BaseProcessor.js","names":["_generator","_interopRequireDefault","require","_shared","_diagnostics","_getClassNameAndSlug","_toCSS","_validateParams","e","__esModule","default","BaseProcessor","SKIP","Symbol","artifacts","dependencies","interpolations","constructor","params","tagSource","astService","location","replacer","displayName","isReferenced","idx","options","context","validateParams","className","slug","getClassNameAndSlug","callee","addDiagnostic","diagnostic","_ref","_diagnostic$end","_this$location","_ref2","_diagnostic$start","_this$location2","push","createProcessorDiagnosticArtifact","end","start","isValidValue","value","isCSSable","hasEvalMeta","toString","tagSourceCode","type","name","generator","code","exports"],"sources":["../src/BaseProcessor.ts"],"sourcesContent":["/* eslint-disable class-methods-use-this */\nimport type { NodePath, types as t } from '@babel/core';\nimport generator from '@babel/generator';\nimport type {\n Expression,\n Identifier,\n SourceLocation,\n MemberExpression,\n} from '@babel/types';\n\nimport type { Artifact, ExpressionValue } from '@wyw-in-js/shared';\nimport { hasEvalMeta } from '@wyw-in-js/shared';\n\nimport { createProcessorDiagnosticArtifact } from './diagnostics';\nimport type {\n IInterpolation,\n Params,\n ProcessorDiagnostic,\n Value,\n ValueCache,\n} from './types';\nimport getClassNameAndSlug from './utils/getClassNameAndSlug';\nimport { isCSSable } from './utils/toCSS';\nimport type { IFileContext, IOptions } from './utils/types';\nimport { validateParams } from './utils/validateParams';\n\nexport { Expression };\n\nexport type ProcessorParams = ConstructorParameters<typeof BaseProcessor>;\nexport type TailProcessorParams = ProcessorParams extends [Params, ...infer T]\n ? T\n : never;\n\nexport type TagSource = {\n imported: string;\n source: string;\n};\n\nexport abstract class BaseProcessor {\n public static SKIP = Symbol('skip');\n\n public readonly artifacts: Artifact[] = [];\n\n public readonly className: string;\n\n public readonly dependencies: ExpressionValue[] = [];\n\n public interpolations: IInterpolation[] = [];\n\n public readonly slug: string;\n\n protected callee: Identifier | MemberExpression;\n\n protected evaluated:\n | Record<'dependencies' | 'expression', Value[]>\n | undefined;\n\n public constructor(\n params: Params,\n public tagSource: TagSource,\n protected readonly astService: typeof t & {\n addDefaultImport: (source: string, nameHint?: string) => Identifier;\n addNamedImport: (\n name: string,\n source: string,\n nameHint?: string\n ) => Identifier;\n },\n public readonly location: SourceLocation | null,\n protected readonly replacer: (\n replacement: Expression | ((tagPath: NodePath) => Expression),\n isPure: boolean\n ) => void,\n public readonly displayName: string,\n public readonly isReferenced: boolean,\n protected readonly idx: number,\n protected readonly options: IOptions,\n protected readonly context: IFileContext\n ) {\n validateParams(\n params,\n ['callee'],\n 'Unknown error: a callee param is not specified'\n );\n\n const { className, slug } = getClassNameAndSlug(\n this.displayName,\n this.idx,\n this.options,\n this.context\n );\n\n this.className = className;\n this.slug = slug;\n\n [[, this.callee]] = params;\n }\n\n /**\n * A replacement for tag referenced in a template literal.\n */\n public abstract get asSelector(): string;\n\n /**\n * A replacement for the tag in evaluation time.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with an object with metadata.\n */\n public abstract get value(): Expression;\n\n public addDiagnostic(diagnostic: ProcessorDiagnostic): void {\n this.artifacts.push(\n createProcessorDiagnosticArtifact({\n ...diagnostic,\n end: diagnostic.end ?? this.location?.end ?? null,\n start: diagnostic.start ?? this.location?.start ?? null,\n })\n );\n }\n\n public isValidValue(value: unknown): value is Value {\n return (\n typeof value === 'function' || isCSSable(value) || hasEvalMeta(value)\n );\n }\n\n public toString(): string {\n return this.tagSourceCode();\n }\n\n protected tagSourceCode(): string {\n if (this.callee.type === 'Identifier') {\n return this.callee.name;\n }\n\n return generator(this.callee).code;\n }\n\n public abstract build(values: ValueCache): void;\n\n /**\n * Perform a replacement for the tag in evaluation time.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with an object with metadata.\n */\n public abstract doEvaltimeReplacement(): void;\n\n /**\n * Perform a replacement for the tag with its runtime version.\n * For example, `css` tag will be replaced with its className,\n * whereas `styled` tag will be replaced with a component.\n * If some parts require evaluated data for render,\n * they will be replaced with placeholders.\n */\n public abstract doRuntimeReplacement(): void;\n}\n"],"mappings":";;;;;;AAEA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AASA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,YAAA,GAAAF,OAAA;AAQA,IAAAG,oBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IA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51 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.TaggedTemplateProcessor = void 0;
7
- var _shared = require("@wyw-in-js/shared");
8
- var _BaseProcessor = require("./BaseProcessor");
9
- var _templateProcessor = _interopRequireDefault(require("./utils/templateProcessor"));
10
- var _validateParams = require("./utils/validateParams");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- class TaggedTemplateProcessor extends _BaseProcessor.BaseProcessor {
13
- #template;
14
- constructor(params, ...args) {
15
- // Should have at least two params and the first one should be a callee.
16
- (0, _validateParams.validateParams)(params, ['callee', '...'], TaggedTemplateProcessor.SKIP);
17
- (0, _validateParams.validateParams)(params, ['callee', 'template'], 'Invalid usage of template tag');
18
- const [tag, [, template]] = params;
19
- super([tag], ...args);
20
- template.forEach(element => {
21
- if ('kind' in element && element.kind !== _shared.ValueType.FUNCTION) {
22
- this.dependencies.push(element);
23
- }
24
- });
25
- this.#template = template;
26
- }
27
- build(values) {
28
- if (this.artifacts.length > 0) {
29
- // FIXME: why it was called twice?
30
- throw new Error('Tag is already built');
31
- }
32
- const artifact = (0, _templateProcessor.default)(this, this.#template, values, this.options.variableNameConfig);
33
- if (artifact) {
34
- this.artifacts.push(['css', artifact]);
35
- }
36
- }
37
- toString() {
38
- return `${super.toString()}\`…\``;
39
- }
40
-
41
- /**
42
- * It is called for each resolved expression in a template literal.
43
- * @param node
44
- * @param precedingCss
45
- * @param source
46
- * @param unit
47
- * @return chunk of CSS that should be added to extracted CSS
48
- */
49
- }
50
- exports.TaggedTemplateProcessor = TaggedTemplateProcessor;
51
- //# sourceMappingURL=TaggedTemplateProcessor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TaggedTemplateProcessor.js","names":["_shared","require","_BaseProcessor","_templateProcessor","_interopRequireDefault","_validateParams","e","__esModule","default","TaggedTemplateProcessor","BaseProcessor","template","constructor","params","args","validateParams","SKIP","tag","forEach","element","kind","ValueType","FUNCTION","dependencies","push","build","values","artifacts","length","Error","artifact","templateProcessor","options","variableNameConfig","toString","exports"],"sources":["../src/TaggedTemplateProcessor.ts"],"sourcesContent":["import type { TemplateElement, Expression, SourceLocation } from '@babel/types';\n\nimport type { ExpressionValue } from '@wyw-in-js/shared';\nimport { ValueType } from '@wyw-in-js/shared';\n\nimport type { TailProcessorParams } from './BaseProcessor';\nimport { BaseProcessor } from './BaseProcessor';\nimport type { ValueCache, Rules, Params } from './types';\nimport templateProcessor from './utils/templateProcessor';\nimport { validateParams } from './utils/validateParams';\n\nexport abstract class TaggedTemplateProcessor extends BaseProcessor {\n readonly #template: (TemplateElement | ExpressionValue)[];\n\n protected constructor(params: Params, ...args: TailProcessorParams) {\n // Should have at least two params and the first one should be a callee.\n validateParams(params, ['callee', '...'], TaggedTemplateProcessor.SKIP);\n\n validateParams(\n params,\n ['callee', 'template'],\n 'Invalid usage of template tag'\n );\n const [tag, [, template]] = params;\n\n super([tag], ...args);\n\n template.forEach((element) => {\n if ('kind' in element && element.kind !== ValueType.FUNCTION) {\n this.dependencies.push(element);\n }\n });\n\n this.#template = template;\n }\n\n public override build(values: ValueCache) {\n if (this.artifacts.length > 0) {\n // FIXME: why it was called twice?\n throw new Error('Tag is already built');\n }\n\n const artifact = templateProcessor(\n this,\n this.#template,\n values,\n this.options.variableNameConfig\n );\n if (artifact) {\n this.artifacts.push(['css', artifact]);\n }\n }\n\n public override toString(): string {\n return `${super.toString()}\\`…\\``;\n }\n\n /**\n * It is called for each resolved expression in a template literal.\n * @param node\n * @param precedingCss\n * @param source\n * @param unit\n * @return chunk of CSS that should be added to extracted CSS\n */\n public abstract addInterpolation(\n node: Expression,\n precedingCss: string,\n source: string,\n unit?: string\n ): string;\n\n public abstract extractRules(\n valueCache: ValueCache,\n cssText: string,\n loc?: SourceLocation | null\n ): Rules;\n}\n"],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AAEA,IA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ACH,IAAI,CAAC,CAAC,KAAK,EAAEM,QAAQ,CAAC,CAAC;IACxC;EACF;EAEgBI,QAAQA,CAAA,EAAW;IACjC,OAAO,GAAG,KAAK,CAACA,QAAQ,CAAC,CAAC,OAAO;EACnC;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AAaA;AAACC,OAAA,CAAA1B,uBAAA,GAAAA,uBAAA","ignoreList":[]}
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isProcessorDiagnosticArtifact = exports.createProcessorDiagnosticArtifact = exports.PROCESSOR_DIAGNOSTIC_ARTIFACT = void 0;
7
- const PROCESSOR_DIAGNOSTIC_ARTIFACT = exports.PROCESSOR_DIAGNOSTIC_ARTIFACT = 'wyw-in-js:diagnostic';
8
- const createProcessorDiagnosticArtifact = diagnostic => [PROCESSOR_DIAGNOSTIC_ARTIFACT, diagnostic];
9
- exports.createProcessorDiagnosticArtifact = createProcessorDiagnosticArtifact;
10
- const isProcessorDiagnosticArtifact = artifact => artifact[0] === PROCESSOR_DIAGNOSTIC_ARTIFACT;
11
- exports.isProcessorDiagnosticArtifact = isProcessorDiagnosticArtifact;
12
- //# sourceMappingURL=diagnostics.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"diagnostics.js","names":["PROCESSOR_DIAGNOSTIC_ARTIFACT","exports","createProcessorDiagnosticArtifact","diagnostic","isProcessorDiagnosticArtifact","artifact"],"sources":["../src/diagnostics.ts"],"sourcesContent":["import type { Artifact } from '@wyw-in-js/shared';\n\nimport type { ProcessorDiagnostic } from './types';\n\nexport const PROCESSOR_DIAGNOSTIC_ARTIFACT = 'wyw-in-js:diagnostic' as const;\n\nexport type ProcessorDiagnosticArtifact = [\n name: typeof PROCESSOR_DIAGNOSTIC_ARTIFACT,\n data: ProcessorDiagnostic,\n];\n\nexport const createProcessorDiagnosticArtifact = (\n diagnostic: ProcessorDiagnostic\n): ProcessorDiagnosticArtifact => [PROCESSOR_DIAGNOSTIC_ARTIFACT, diagnostic];\n\nexport const isProcessorDiagnosticArtifact = (\n artifact: Artifact\n): artifact is ProcessorDiagnosticArtifact =>\n artifact[0] === PROCESSOR_DIAGNOSTIC_ARTIFACT;\n"],"mappings":";;;;;;AAIO,MAAMA,6BAA6B,GAAAC,OAAA,CAAAD,6BAAA,GAAG,sBAA+B;AAOrE,MAAME,iCAAiC,GAC5CC,UAA+B,IACC,CAACH,6BAA6B,EAAEG,UAAU,CAAC;AAACF,OAAA,CAAAC,iCAAA,GAAAA,iCAAA;AAEvE,MAAME,6BAA6B,GACxCC,QAAkB,IAElBA,QAAQ,CAAC,CAAC,CAAC,KAAKL,6BAA6B;AAACC,OAAA,CAAAG,6BAAA,GAAAA,6BAAA","ignoreList":[]}
package/lib/index.js DELETED
@@ -1,89 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- BaseProcessor: true,
8
- createProcessorDiagnosticArtifact: true,
9
- isProcessorDiagnosticArtifact: true,
10
- PROCESSOR_DIAGNOSTIC_ARTIFACT: true,
11
- buildSlug: true,
12
- isValidParams: true,
13
- validateParams: true,
14
- TaggedTemplateProcessor: true,
15
- toValidCSSIdentifier: true
16
- };
17
- Object.defineProperty(exports, "BaseProcessor", {
18
- enumerable: true,
19
- get: function () {
20
- return _BaseProcessor.BaseProcessor;
21
- }
22
- });
23
- Object.defineProperty(exports, "PROCESSOR_DIAGNOSTIC_ARTIFACT", {
24
- enumerable: true,
25
- get: function () {
26
- return _diagnostics.PROCESSOR_DIAGNOSTIC_ARTIFACT;
27
- }
28
- });
29
- Object.defineProperty(exports, "TaggedTemplateProcessor", {
30
- enumerable: true,
31
- get: function () {
32
- return _TaggedTemplateProcessor.TaggedTemplateProcessor;
33
- }
34
- });
35
- Object.defineProperty(exports, "buildSlug", {
36
- enumerable: true,
37
- get: function () {
38
- return _buildSlug.buildSlug;
39
- }
40
- });
41
- Object.defineProperty(exports, "createProcessorDiagnosticArtifact", {
42
- enumerable: true,
43
- get: function () {
44
- return _diagnostics.createProcessorDiagnosticArtifact;
45
- }
46
- });
47
- Object.defineProperty(exports, "isProcessorDiagnosticArtifact", {
48
- enumerable: true,
49
- get: function () {
50
- return _diagnostics.isProcessorDiagnosticArtifact;
51
- }
52
- });
53
- Object.defineProperty(exports, "isValidParams", {
54
- enumerable: true,
55
- get: function () {
56
- return _validateParams.isValidParams;
57
- }
58
- });
59
- Object.defineProperty(exports, "toValidCSSIdentifier", {
60
- enumerable: true,
61
- get: function () {
62
- return _toValidCSSIdentifier.toValidCSSIdentifier;
63
- }
64
- });
65
- Object.defineProperty(exports, "validateParams", {
66
- enumerable: true,
67
- get: function () {
68
- return _validateParams.validateParams;
69
- }
70
- });
71
- var _BaseProcessor = require("./BaseProcessor");
72
- var _diagnostics = require("./diagnostics");
73
- var _types = require("./types");
74
- Object.keys(_types).forEach(function (key) {
75
- if (key === "default" || key === "__esModule") return;
76
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
77
- if (key in exports && exports[key] === _types[key]) return;
78
- Object.defineProperty(exports, key, {
79
- enumerable: true,
80
- get: function () {
81
- return _types[key];
82
- }
83
- });
84
- });
85
- var _buildSlug = require("./utils/buildSlug");
86
- var _validateParams = require("./utils/validateParams");
87
- var _TaggedTemplateProcessor = require("./TaggedTemplateProcessor");
88
- var _toValidCSSIdentifier = require("./utils/toValidCSSIdentifier");
89
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_BaseProcessor","require","_diagnostics","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_buildSlug","_validateParams","_TaggedTemplateProcessor","_toValidCSSIdentifier"],"sources":["../src/index.ts"],"sourcesContent":["export { BaseProcessor } from './BaseProcessor';\nexport {\n createProcessorDiagnosticArtifact,\n isProcessorDiagnosticArtifact,\n PROCESSOR_DIAGNOSTIC_ARTIFACT,\n} from './diagnostics';\nexport type { ProcessorDiagnosticArtifact } from './diagnostics';\nexport type {\n Expression,\n TagSource,\n ProcessorParams,\n TailProcessorParams,\n} from './BaseProcessor';\nexport * from './types';\nexport { buildSlug } from './utils/buildSlug';\nexport type { IOptions, IFileContext } from './utils/types';\nexport { isValidParams, validateParams } from './utils/validateParams';\nexport type { MapParams, ParamConstraints } from './utils/validateParams';\nexport { TaggedTemplateProcessor } from './TaggedTemplateProcessor';\nexport { toValidCSSIdentifier } from './utils/toValidCSSIdentifier';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAYA,IAAAE,MAAA,GAAAF,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,UAAA,GAAAf,OAAA;AAEA,IAAAgB,eAAA,GAAAhB,OAAA;AAEA,IAAAiB,wBAAA,GAAAjB,OAAA;AACA,IAAAkB,qBAAA,GAAAlB,OAAA","ignoreList":[]}
package/lib/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=types.js.map
package/lib/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {\n Expression,\n Identifier,\n TemplateElement,\n MemberExpression,\n} from '@babel/types';\n\nimport type { ExpressionValue, Location, WYWEvalMeta } from '@wyw-in-js/shared';\n\nexport type CSSPropertyValue = string | number;\n\nexport type ObjectWithSelectors = {\n [key: string]:\n | ObjectWithSelectors\n | CSSPropertyValue\n | (ObjectWithSelectors | CSSPropertyValue)[];\n};\n\nexport type CSSable = ObjectWithSelectors[string];\n\nexport type Value = (() => void) | WYWEvalMeta | CSSable;\n\nexport type ValueCache = Map<string | number | boolean | null, unknown>;\n\nexport interface ICSSRule {\n atom?: boolean;\n className: string;\n cssText: string;\n displayName: string;\n start: Location | null | undefined;\n}\n\nexport interface IInterpolation {\n id: string;\n node: Expression;\n source: string;\n unit: string;\n}\n\nexport type ProcessorDiagnosticSeverity = 'error' | 'warning';\n\nexport type ProcessorDiagnostic = {\n category: string;\n end?: Location | null;\n message: string;\n severity: ProcessorDiagnosticSeverity;\n start?: Location | null;\n};\n\nexport type Rules = Record<string, ICSSRule>;\n\nexport type CalleeParam = readonly ['callee', Identifier | MemberExpression];\nexport type CallParam = readonly ['call', ...ExpressionValue[]];\nexport type MemberParam = readonly ['member', string];\nexport type TemplateParam = readonly [\n 'template',\n (TemplateElement | ExpressionValue)[],\n];\n\nexport type Param = CalleeParam | CallParam | MemberParam | TemplateParam;\nexport type Params = readonly Param[];\n"],"mappings":"","ignoreList":[]}
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.buildSlug = buildSlug;
7
- const PLACEHOLDER = /\[(.*?)]/g;
8
- const isValidArgName = (key, args) => key in args;
9
- function buildSlug(pattern, args) {
10
- return pattern.replace(PLACEHOLDER, (_, name) => isValidArgName(name, args) ? args[name].toString() : '');
11
- }
12
- //# sourceMappingURL=buildSlug.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildSlug.js","names":["PLACEHOLDER","isValidArgName","key","args","buildSlug","pattern","replace","_","name","toString"],"sources":["../../src/utils/buildSlug.ts"],"sourcesContent":["const PLACEHOLDER = /\\[(.*?)]/g;\n\nconst isValidArgName = <TArgs extends Record<string, { toString(): string }>>(\n key: string | number | symbol,\n args: TArgs\n): key is keyof TArgs => key in args;\n\nexport function buildSlug<TArgs extends Record<string, { toString(): string }>>(\n pattern: string,\n args: TArgs\n) {\n return pattern.replace(PLACEHOLDER, (_, name: string) =>\n isValidArgName(name, args) ? args[name].toString() : ''\n );\n}\n"],"mappings":";;;;;;AAAA,MAAMA,WAAW,GAAG,WAAW;AAE/B,MAAMC,cAAc,GAAGA,CACrBC,GAA6B,EAC7BC,IAAW,KACYD,GAAG,IAAIC,IAAI;AAE7B,SAASC,SAASA,CACvBC,OAAe,EACfF,IAAW,EACX;EACA,OAAOE,OAAO,CAACC,OAAO,CAACN,WAAW,EAAE,CAACO,CAAC,EAAEC,IAAY,KAClDP,cAAc,CAACO,IAAI,EAAEL,IAAI,CAAC,GAAGA,IAAI,CAACK,IAAI,CAAC,CAACC,QAAQ,CAAC,CAAC,GAAG,EACvD,CAAC;AACH","ignoreList":[]}
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = getClassNameAndSlug;
7
- var _path = require("path");
8
- var _shared = require("@wyw-in-js/shared");
9
- var _buildSlug = require("./buildSlug");
10
- var _toValidCSSIdentifier = require("./toValidCSSIdentifier");
11
- function getClassNameAndSlug(displayName, idx, options, context) {
12
- var _context$filename;
13
- const relativeFilename = (context.root && context.filename ? (0, _path.relative)(context.root, context.filename) : (_context$filename = context.filename) !== null && _context$filename !== void 0 ? _context$filename : 'unknown').replace(/\\/g, _path.posix.sep);
14
-
15
- // Custom properties need to start with a letter, so we prefix the slug
16
- // Also use append the index of the class to the filename for uniqueness in the file
17
- const slug = (0, _toValidCSSIdentifier.toValidCSSIdentifier)(`${displayName.charAt(0).toLowerCase()}${(0, _shared.slugify)(`${relativeFilename}:${idx}`)}`);
18
-
19
- // Collect some useful replacement patterns from the filename
20
- // Available variables for the square brackets used in `classNameSlug` options
21
- const ext = (0, _path.extname)(relativeFilename);
22
- const slugVars = {
23
- hash: slug,
24
- title: displayName,
25
- index: idx,
26
- file: relativeFilename,
27
- ext,
28
- name: (0, _path.basename)(relativeFilename, ext),
29
- dir: (0, _path.dirname)(relativeFilename).split(_path.sep).pop()
30
- };
31
- let className = options.displayName ? `${(0, _toValidCSSIdentifier.toValidCSSIdentifier)(displayName)}_${slug}` : slug;
32
-
33
- // The className can be defined by the user either as fn or a string
34
- if (typeof options.classNameSlug === 'function') {
35
- try {
36
- className = (0, _toValidCSSIdentifier.toValidCSSIdentifier)(options.classNameSlug(slug, displayName, slugVars));
37
- } catch {
38
- throw new Error('classNameSlug option must return a string');
39
- }
40
- }
41
- if (typeof options.classNameSlug === 'string') {
42
- className = (0, _toValidCSSIdentifier.toValidCSSIdentifier)((0, _buildSlug.buildSlug)(options.classNameSlug, slugVars));
43
- }
44
- _shared.logger.extend('template-parse:generated-meta')(`slug: ${slug}, displayName: ${displayName}, className: ${className}`);
45
- return {
46
- className,
47
- slug
48
- };
49
- }
50
- //# sourceMappingURL=getClassNameAndSlug.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getClassNameAndSlug.js","names":["_path","require","_shared","_buildSlug","_toValidCSSIdentifier","getClassNameAndSlug","displayName","idx","options","context","_context$filename","relativeFilename","root","filename","relative","replace","posix","sep","slug","toValidCSSIdentifier","charAt","toLowerCase","slugify","ext","extname","slugVars","hash","title","index","file","name","basename","dir","dirname","split","pop","className","classNameSlug","Error","buildSlug","logger","extend"],"sources":["../../src/utils/getClassNameAndSlug.ts"],"sourcesContent":["import { basename, dirname, extname, relative, sep, posix } from 'path';\n\nimport type { ClassNameSlugVars } from '@wyw-in-js/shared';\nimport { logger, slugify } from '@wyw-in-js/shared';\n\nimport { buildSlug } from './buildSlug';\nimport { toValidCSSIdentifier } from './toValidCSSIdentifier';\nimport type { IFileContext, IOptions } from './types';\n\nexport default function getClassNameAndSlug(\n displayName: string,\n idx: number,\n options: IOptions,\n context: IFileContext\n): { className: string; slug: string } {\n const relativeFilename = (\n context.root && context.filename\n ? relative(context.root, context.filename)\n : context.filename ?? 'unknown'\n ).replace(/\\\\/g, posix.sep);\n\n // Custom properties need to start with a letter, so we prefix the slug\n // Also use append the index of the class to the filename for uniqueness in the file\n const slug = toValidCSSIdentifier(\n `${displayName.charAt(0).toLowerCase()}${slugify(\n `${relativeFilename}:${idx}`\n )}`\n );\n\n // Collect some useful replacement patterns from the filename\n // Available variables for the square brackets used in `classNameSlug` options\n const ext = extname(relativeFilename);\n const slugVars: ClassNameSlugVars = {\n hash: slug,\n title: displayName,\n index: idx,\n file: relativeFilename,\n ext,\n name: basename(relativeFilename, ext),\n dir: dirname(relativeFilename).split(sep).pop() as string,\n };\n\n let className = options.displayName\n ? `${toValidCSSIdentifier(displayName!)}_${slug!}`\n : slug!;\n\n // The className can be defined by the user either as fn or a string\n if (typeof options.classNameSlug === 'function') {\n try {\n className = toValidCSSIdentifier(\n options.classNameSlug(slug, displayName, slugVars)\n );\n } catch {\n throw new Error('classNameSlug option must return a string');\n }\n }\n\n if (typeof options.classNameSlug === 'string') {\n className = toValidCSSIdentifier(\n buildSlug(options.classNameSlug, slugVars)\n );\n }\n\n logger.extend('template-parse:generated-meta')(\n `slug: ${slug}, displayName: ${displayName}, className: ${className}`\n );\n\n return { className, slug };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAGA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AAGe,SAASI,mBAAmBA,CACzCC,WAAmB,EACnBC,GAAW,EACXC,OAAiB,EACjBC,OAAqB,EACgB;EAAA,IAAAC,iBAAA;EACrC,MAAMC,gBAAgB,GAAG,CACvBF,OAAO,CAAC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,2CAA2C,CAAC;IAC9D;EACF;EAEA,IAAI,OAAO9B,OAAO,CAAC6B,aAAa,KAAK,QAAQ,EAAE;IAC7CD,SAAS,GAAG,IAAAjB,0CAAoB,EAC9B,IAAAoB,oBAAS,EAAC/B,OAAO,CAAC6B,aAAa,EAAEZ,QAAQ,CAC3C,CAAC;EACH;EAEAe,cAAM,CAACC,MAAM,CAAC,+BAA+B,CAAC,CAC5C,SAASvB,IAAI,kBAAkBZ,WAAW,gBAAgB8B,SAAS,EACrE,CAAC;EAED,OAAO;IAAEA,SAAS;IAAElB;EAAK,CAAC;AAC5B","ignoreList":[]}
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getVariableName = getVariableName;
7
- function getVariableName(varId, rawVariableName) {
8
- switch (rawVariableName) {
9
- case 'raw':
10
- return varId;
11
- case 'dashes':
12
- return `--${varId}`;
13
- case 'var':
14
- default:
15
- return `var(--${varId})`;
16
- }
17
- }
18
- //# sourceMappingURL=getVariableName.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getVariableName.js","names":["getVariableName","varId","rawVariableName"],"sources":["../../src/utils/getVariableName.ts"],"sourcesContent":["import type { IOptions } from './types';\n\nexport function getVariableName(\n varId: string,\n rawVariableName: IOptions['variableNameConfig'] | undefined\n) {\n switch (rawVariableName) {\n case 'raw':\n return varId;\n case 'dashes':\n return `--${varId}`;\n case 'var':\n default:\n return `var(--${varId})`;\n }\n}\n"],"mappings":";;;;;;AAEO,SAASA,eAAeA,CAC7BC,KAAa,EACbC,eAA2D,EAC3D;EACA,QAAQA,eAAe;IACrB,KAAK,KAAK;MACR,OAAOD,KAAK;IACd,KAAK,QAAQ;MACX,OAAO,KAAKA,KAAK,EAAE;IACrB,KAAK,KAAK;IACV;MACE,OAAO,SAASA,KAAK,GAAG;EAC5B;AACF","ignoreList":[]}
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = stripLines;
7
- // Stripping away the new lines ensures that we preserve line numbers
8
- // This is useful in case of tools such as the stylelint pre-processor
9
- // This should be safe because strings cannot contain newline: https://www.w3.org/TR/CSS2/syndata.html#strings
10
- function stripLines(loc, text) {
11
- let result = String(text).replace(/[\r\n]+/g, ' ').trim();
12
-
13
- // If the start and end line numbers aren't same, add new lines to span the text across multiple lines
14
- if (loc.start.line !== loc.end.line) {
15
- result += '\n'.repeat(loc.end.line - loc.start.line);
16
-
17
- // Add extra spaces to offset the column
18
- result += ' '.repeat(loc.end.column);
19
- }
20
- return result;
21
- }
22
- //# sourceMappingURL=stripLines.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stripLines.js","names":["stripLines","loc","text","result","String","replace","trim","start","line","end","repeat","column"],"sources":["../../src/utils/stripLines.ts"],"sourcesContent":["import type { Location } from '@wyw-in-js/shared';\n\n// Stripping away the new lines ensures that we preserve line numbers\n// This is useful in case of tools such as the stylelint pre-processor\n// This should be safe because strings cannot contain newline: https://www.w3.org/TR/CSS2/syndata.html#strings\nexport default function stripLines(\n loc: { end: Location; start: Location },\n text: string | number\n) {\n let result = String(text)\n .replace(/[\\r\\n]+/g, ' ')\n .trim();\n\n // If the start and end line numbers aren't same, add new lines to span the text across multiple lines\n if (loc.start.line !== loc.end.line) {\n result += '\\n'.repeat(loc.end.line - loc.start.line);\n\n // Add extra spaces to offset the column\n result += ' '.repeat(loc.end.column);\n }\n\n return result;\n}\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACe,SAASA,UAAUA,CAChCC,GAAuC,EACvCC,IAAqB,EACrB;EACA,IAAIC,MAAM,GAAGC,MAAM,CAACF,IAAI,CAAC,CACtBG,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CACxBC,IAAI,CAAC,CAAC;;EAET;EACA,IAAIL,GAAG,CAACM,KAAK,CAACC,IAAI,KAAKP,GAAG,CAACQ,GAAG,CAACD,IAAI,EAAE;IACnCL,MAAM,IAAI,IAAI,CAACO,MAAM,CAACT,GAAG,CAACQ,GAAG,CAACD,IAAI,GAAGP,GAAG,CAACM,KAAK,CAACC,IAAI,CAAC;;IAEpD;IACAL,MAAM,IAAI,GAAG,CAACO,MAAM,CAACT,GAAG,CAACQ,GAAG,CAACE,MAAM,CAAC;EACtC;EAEA,OAAOR,MAAM;AACf","ignoreList":[]}
@@ -1,129 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = templateProcessor;
7
- var _shared = require("@wyw-in-js/shared");
8
- var _getVariableName = require("./getVariableName");
9
- var _stripLines = _interopRequireDefault(require("./stripLines"));
10
- var _throwIfInvalid = _interopRequireDefault(require("./throwIfInvalid"));
11
- var _toCSS = _interopRequireWildcard(require("./toCSS"));
12
- var _units = require("./units");
13
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- /* eslint-disable no-continue */
16
- /**
17
- * This file handles transforming template literals to class names or styled components and generates CSS content.
18
- * It uses CSS code from template literals and evaluated values of lazy dependencies stored in ValueCache.
19
- */
20
-
21
- // Match any valid CSS unit not immediately followed by an alphanumeric character or underscore.
22
- const unitRegex = new RegExp(`^(?:${_units.units.join('|')})(?![a-zA-Z0-9_])`);
23
- function templateProcessor(tagProcessor, [...template], valueCache, variableNameConfig) {
24
- const sourceMapReplacements = [];
25
- // Check if the variable is referenced anywhere for basic DCE
26
- // Only works when it's assigned to a variable
27
- const {
28
- isReferenced
29
- } = tagProcessor;
30
-
31
- // Serialize the tagged template literal to a string
32
- let cssText = '';
33
- let item;
34
- // eslint-disable-next-line no-cond-assign
35
- while (item = template.shift()) {
36
- if ('type' in item) {
37
- // It's a template element
38
- cssText += item.value.cooked;
39
- continue;
40
- }
41
-
42
- // It's an expression
43
- const {
44
- ex
45
- } = item;
46
- const {
47
- end,
48
- start
49
- } = ex.loc;
50
- const beforeLength = cssText.length;
51
-
52
- // The location will be end of the current string to start of next string
53
- const next = template[0]; // template[0] is the next template element
54
- const loc = {
55
- start,
56
- end: next ? {
57
- line: next.loc.start.line,
58
- column: next.loc.start.column
59
- } : {
60
- line: end.line,
61
- column: end.column + 1
62
- }
63
- };
64
- const value = 'value' in item ? item.value : valueCache.get(item.ex.name);
65
-
66
- // Is it props based interpolation?
67
- if (item.kind === _shared.ValueType.FUNCTION || typeof value === 'function') {
68
- var _next$value$cooked;
69
- // Check if previous expression was a CSS variable that we replaced
70
- // If it has a unit after it, we need to move the unit into the interpolation
71
- // e.g. `var(--size)px` should actually be `var(--size)`
72
- // So we check if the current text starts with a unit, and add the unit to the previous interpolation
73
- // Another approach would be `calc(var(--size) * 1px), but some browsers don't support all units
74
- // https://bugzilla.mozilla.org/show_bug.cgi?id=956573
75
- const matches = (_next$value$cooked = next.value.cooked) === null || _next$value$cooked === void 0 ? void 0 : _next$value$cooked.match(unitRegex);
76
- try {
77
- if (matches) {
78
- var _next$value$cooked$su, _next$value$cooked2, _unit$length;
79
- template.shift();
80
- const [unit] = matches;
81
- const varId = tagProcessor.addInterpolation(item.ex, cssText, item.source, unit);
82
- cssText += (0, _getVariableName.getVariableName)(varId, variableNameConfig);
83
- cssText += (_next$value$cooked$su = (_next$value$cooked2 = next.value.cooked) === null || _next$value$cooked2 === void 0 ? void 0 : _next$value$cooked2.substring((_unit$length = unit === null || unit === void 0 ? void 0 : unit.length) !== null && _unit$length !== void 0 ? _unit$length : 0)) !== null && _next$value$cooked$su !== void 0 ? _next$value$cooked$su : '';
84
- } else {
85
- const varId = tagProcessor.addInterpolation(item.ex, cssText, item.source);
86
- cssText += (0, _getVariableName.getVariableName)(varId, variableNameConfig);
87
- }
88
- } catch (e) {
89
- if (e instanceof Error) {
90
- throw item.buildCodeFrameError(e.message);
91
- }
92
- throw e;
93
- }
94
- } else {
95
- (0, _throwIfInvalid.default)(tagProcessor.isValidValue.bind(tagProcessor), value, item, item.source);
96
- if (value !== undefined && typeof value !== 'function') {
97
- // Skip the blank string instead of throw ing an error
98
- if (value === '') {
99
- continue;
100
- }
101
- if ((0, _shared.hasEvalMeta)(value)) {
102
- // If it's a React component wrapped in styled, get the class name
103
- // Useful for interpolating components
104
- cssText += `.${value.__wyw_meta.className}`;
105
- } else if ((0, _toCSS.isCSSable)(value)) {
106
- // If it's a plain object or an array, convert it to a CSS string
107
- cssText += (0, _stripLines.default)(loc, (0, _toCSS.default)(value));
108
- } else {
109
- // For anything else, assume it'll be stringified
110
- cssText += (0, _stripLines.default)(loc, value);
111
- }
112
- sourceMapReplacements.push({
113
- original: loc,
114
- length: cssText.length - beforeLength
115
- });
116
- }
117
- }
118
- }
119
- const rules = tagProcessor.extractRules(valueCache, cssText, tagProcessor.location);
120
-
121
- // tagProcessor.doRuntimeReplacement(classes);
122
- if (!isReferenced && !cssText.includes(':global')) {
123
- return null;
124
- }
125
-
126
- // eslint-disable-next-line no-param-reassign
127
- return [rules, sourceMapReplacements];
128
- }
129
- //# sourceMappingURL=templateProcessor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"templateProcessor.js","names":["_shared","require","_getVariableName","_stripLines","_interopRequireDefault","_throwIfInvalid","_toCSS","_interopRequireWildcard","_units","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","unitRegex","RegExp","units","join","templateProcessor","tagProcessor","template","valueCache","variableNameConfig","sourceMapReplacements","isReferenced","cssText","item","shift","value","cooked","ex","end","start","loc","beforeLength","length","next","line","column","name","kind","ValueType","FUNCTION","_next$value$cooked","matches","match","_next$value$cooked$su","_next$value$cooked2","_unit$length","unit","varId","addInterpolation","source","getVariableName","substring","Error","buildCodeFrameError","message","throwIfInvalid","isValidValue","bind","undefined","hasEvalMeta","__wyw_meta","className","isCSSable","stripLines","toCSS","push","original","rules","extractRules","location","includes"],"sources":["../../src/utils/templateProcessor.ts"],"sourcesContent":["/* eslint-disable no-continue */\n/**\n * This file handles transforming template literals to class names or styled components and generates CSS content.\n * It uses CSS code from template literals and evaluated values of lazy dependencies stored in ValueCache.\n */\n\nimport type { TemplateElement } from '@babel/types';\n\nimport type { ExpressionValue, Replacements } from '@wyw-in-js/shared';\nimport { hasEvalMeta, ValueType } from '@wyw-in-js/shared';\n\nimport type { TaggedTemplateProcessor } from '../TaggedTemplateProcessor';\nimport type { ValueCache, Rules } from '../types';\n\nimport { getVariableName } from './getVariableName';\nimport stripLines from './stripLines';\nimport throwIfInvalid from './throwIfInvalid';\nimport toCSS, { isCSSable } from './toCSS';\nimport type { IOptions } from './types';\nimport { units } from './units';\n\n// Match any valid CSS unit not immediately followed by an alphanumeric character or underscore.\nconst unitRegex = new RegExp(`^(?:${units.join('|')})(?![a-zA-Z0-9_])`);\n\nexport default function templateProcessor(\n tagProcessor: TaggedTemplateProcessor,\n [...template]: (TemplateElement | ExpressionValue)[],\n valueCache: ValueCache,\n variableNameConfig: IOptions['variableNameConfig'] | undefined\n): [rules: Rules, sourceMapReplacements: Replacements] | null {\n const sourceMapReplacements: Replacements = [];\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n const { isReferenced } = tagProcessor;\n\n // Serialize the tagged template literal to a string\n let cssText = '';\n\n let item: TemplateElement | ExpressionValue | undefined;\n // eslint-disable-next-line no-cond-assign\n while ((item = template.shift())) {\n if ('type' in item) {\n // It's a template element\n cssText += item.value.cooked;\n continue;\n }\n\n // It's an expression\n const { ex } = item;\n\n const { end, start } = ex.loc!;\n const beforeLength = cssText.length;\n\n // The location will be end of the current string to start of next string\n const next = template[0] as TemplateElement; // template[0] is the next template element\n const loc = {\n start,\n end: next\n ? { line: next.loc!.start.line, column: next.loc!.start.column }\n : { line: end.line, column: end.column + 1 },\n };\n\n const value = 'value' in item ? item.value : valueCache.get(item.ex.name);\n\n // Is it props based interpolation?\n if (item.kind === ValueType.FUNCTION || typeof value === 'function') {\n // Check if previous expression was a CSS variable that we replaced\n // If it has a unit after it, we need to move the unit into the interpolation\n // e.g. `var(--size)px` should actually be `var(--size)`\n // So we check if the current text starts with a unit, and add the unit to the previous interpolation\n // Another approach would be `calc(var(--size) * 1px), but some browsers don't support all units\n // https://bugzilla.mozilla.org/show_bug.cgi?id=956573\n const matches = next.value.cooked?.match(unitRegex);\n\n try {\n if (matches) {\n template.shift();\n const [unit] = matches;\n\n const varId = tagProcessor.addInterpolation(\n item.ex,\n cssText,\n item.source,\n unit\n );\n cssText += getVariableName(varId, variableNameConfig);\n\n cssText += next.value.cooked?.substring(unit?.length ?? 0) ?? '';\n } else {\n const varId = tagProcessor.addInterpolation(\n item.ex,\n cssText,\n item.source\n );\n cssText += getVariableName(varId, variableNameConfig);\n }\n } catch (e) {\n if (e instanceof Error) {\n throw item.buildCodeFrameError(e.message);\n }\n\n throw e;\n }\n } else {\n throwIfInvalid(\n tagProcessor.isValidValue.bind(tagProcessor),\n value,\n item,\n item.source\n );\n\n if (value !== undefined && typeof value !== 'function') {\n // Skip the blank string instead of throw ing an error\n if (value === '') {\n continue;\n }\n\n if (hasEvalMeta(value)) {\n // If it's a React component wrapped in styled, get the class name\n // Useful for interpolating components\n cssText += `.${value.__wyw_meta.className}`;\n } else if (isCSSable(value)) {\n // If it's a plain object or an array, convert it to a CSS string\n cssText += stripLines(loc, toCSS(value));\n } else {\n // For anything else, assume it'll be stringified\n cssText += stripLines(loc, value);\n }\n\n sourceMapReplacements.push({\n original: loc,\n length: cssText.length - beforeLength,\n });\n }\n }\n }\n\n const rules = tagProcessor.extractRules(\n valueCache,\n cssText,\n tagProcessor.location\n );\n\n // tagProcessor.doRuntimeReplacement(classes);\n if (!isReferenced && !cssText.includes(':global')) {\n return null;\n }\n\n // eslint-disable-next-line no-param-reassign\n return [rules, sourceMapReplacements];\n}\n"],"mappings":";;;;;;AASA,IAAAA,OAAA,GAAAC,OAAA;AAKA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,eAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,MAAA,GAAAC,uBAAA,CAAAN,OAAA;AAEA,IAAAO,MAAA,GAAAP,OAAA;AAAgC,SAAAM,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,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rClD,UAAU,EACVI,OAAO,EACPN,YAAY,CAACqD,QACf,CAAC;;EAED;EACA,IAAI,CAAChD,YAAY,IAAI,CAACC,OAAO,CAACgD,QAAQ,CAAC,SAAS,CAAC,EAAE;IACjD,OAAO,IAAI;EACb;;EAEA;EACA,OAAO,CAACH,KAAK,EAAE/C,qBAAqB,CAAC;AACvC","ignoreList":[]}
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- const isLikeError = value => typeof value === 'object' && value !== null && 'stack' in value && 'message' in value;
8
-
9
- // Throw if we can't handle the interpolated value
10
- function throwIfInvalid(checker, value, ex, source) {
11
- // We can't use instanceof here so let's use duck typing
12
- if (isLikeError(value) && value.stack && value.message) {
13
- throw ex.buildCodeFrameError(`An error occurred when evaluating the expression:
14
-
15
- > ${value.message}.
16
-
17
- Make sure you are not using a browser or Node specific API and all the variables are available in static context.
18
- Linaria have to extract pieces of your code to resolve the interpolated values.
19
- Defining styled component or class will not work inside:
20
- - function,
21
- - class,
22
- - method,
23
- - loop,
24
- because it cannot be statically determined in which context you use them.
25
- That's why some variables may be not defined during evaluation.
26
- `);
27
- }
28
- if (checker(value)) {
29
- return;
30
- }
31
- const stringified = typeof value === 'object' ? JSON.stringify(value) : String(value);
32
- throw ex.buildCodeFrameError(`The expression evaluated to '${stringified}', which is probably a mistake. If you want it to be inserted into CSS, explicitly cast or transform the value to a string, e.g. - 'String(${source})'.`);
33
- }
34
- var _default = exports.default = throwIfInvalid;
35
- //# sourceMappingURL=throwIfInvalid.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"throwIfInvalid.js","names":["isLikeError","value","throwIfInvalid","checker","ex","source","stack","message","buildCodeFrameError","stringified","JSON","stringify","String","_default","exports","default"],"sources":["../../src/utils/throwIfInvalid.ts"],"sourcesContent":["import type { BuildCodeFrameErrorFn } from '@wyw-in-js/shared';\n\nconst isLikeError = (value: unknown): value is Error =>\n typeof value === 'object' &&\n value !== null &&\n 'stack' in value &&\n 'message' in value;\n\n// Throw if we can't handle the interpolated value\nfunction throwIfInvalid<T>(\n checker: (value: unknown) => value is T,\n value: Error | unknown,\n ex: { buildCodeFrameError: BuildCodeFrameErrorFn },\n source: string\n): asserts value is T {\n // We can't use instanceof here so let's use duck typing\n if (isLikeError(value) && value.stack && value.message) {\n throw ex.buildCodeFrameError(\n `An error occurred when evaluating the expression:\n\n > ${value.message}.\n\n Make sure you are not using a browser or Node specific API and all the variables are available in static context.\n Linaria have to extract pieces of your code to resolve the interpolated values.\n Defining styled component or class will not work inside:\n - function,\n - class,\n - method,\n - loop,\n because it cannot be statically determined in which context you use them.\n That's why some variables may be not defined during evaluation.\n `\n );\n }\n\n if (checker(value)) {\n return;\n }\n\n const stringified =\n typeof value === 'object' ? JSON.stringify(value) : String(value);\n\n throw ex.buildCodeFrameError(\n `The expression evaluated to '${stringified}', which is probably a mistake. If you want it to be inserted into CSS, explicitly cast or transform the value to a string, e.g. - 'String(${source})'.`\n );\n}\n\nexport default throwIfInvalid;\n"],"mappings":";;;;;;AAEA,MAAMA,WAAW,GAAIC,KAAc,IACjC,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,OAAO,IAAIA,KAAK,IAChB,SAAS,IAAIA,KAAK;;AAEpB;AACA,SAASC,cAAcA,CACrBC,OAAuC,EACvCF,KAAsB,EACtBG,EAAkD,EAClDC,MAAc,EACM;EACpB;EACA,IAAIL,WAAW,CAACC,KAAK,CAAC,IAAIA,KAAK,CAACK,KAAK,IAAIL,KAAK,CAACM,OAAO,EAAE;IACtD,MAAMH,EAAE,CAACI,mBAAmB,CAC1B;AACN;AACA,MAAMP,KAAK,CAACM,OAAO;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OACI,CAAC;EACH;EAEA,IAAIJ,OAAO,CAACF,KAAK,CAAC,EAAE;IAClB;EACF;EAEA,MAAMQ,WAAW,GACf,OAAOR,KAAK,KAAK,QAAQ,GAAGS,IAAI,CAACC,SAAS,CAACV,KAAK,CAAC,GAAGW,MAAM,CAACX,KAAK,CAAC;EAEnE,MAAMG,EAAE,CAACI,mBAAmB,CAC1B,gCAAgCC,WAAW,8IAA8IJ,MAAM,KACjM,CAAC;AACH;AAAC,IAAAQ,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcb,cAAc","ignoreList":[]}