@wyw-in-js/processor-utils 0.7.0 → 0.8.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.
@@ -11,8 +11,8 @@ import throwIfInvalid from './throwIfInvalid';
11
11
  import toCSS, { isCSSable } from './toCSS';
12
12
  import { units } from './units';
13
13
 
14
- // Match any valid CSS units followed by a separator such as ;, newline etc.
15
- const unitRegex = new RegExp(`^(?:${units.join('|')})\\b`);
14
+ // Match any valid CSS unit not immediately followed by an alphanumeric character or underscore.
15
+ const unitRegex = new RegExp(`^(?:${units.join('|')})(?![a-zA-Z0-9_])`);
16
16
  export default function templateProcessor(tagProcessor, [...template], valueCache, variableNameConfig) {
17
17
  const sourceMapReplacements = [];
18
18
  // Check if the variable is referenced anywhere for basic DCE
@@ -1 +1 @@
1
- {"version":3,"file":"templateProcessor.js","names":["hasEvalMeta","ValueType","getVariableName","stripLines","throwIfInvalid","toCSS","isCSSable","units","unitRegex","RegExp","join","templateProcessor","tagProcessor","template","valueCache","variableNameConfig","sourceMapReplacements","isReferenced","cssText","item","shift","value","cooked","ex","end","start","loc","beforeLength","length","next","line","column","get","name","kind","FUNCTION","matches","match","unit","varId","addInterpolation","source","substring","e","Error","buildCodeFrameError","message","isValidValue","bind","undefined","__wyw_meta","className","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 units followed by a separator such as ;, newline etc.\nconst unitRegex = new RegExp(`^(?:${units.join('|')})\\\\b`);\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":"AAAA;AACA;AACA;AACA;AACA;;AAKA,SAASA,WAAW,EAAEC,SAAS,QAAQ,mBAAmB;AAK1D,SAASC,eAAe,QAAQ,mBAAmB;AACnD,OAAOC,UAAU,MAAM,cAAc;AACrC,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,KAAK,IAAIC,SAAS,QAAQ,SAAS;AAE1C,SAASC,KAAK,QAAQ,SAAS;;AAE/B;AACA,MAAMC,SAAS,GAAG,IAAIC,MAAM,CAAE,OAAMF,KAAK,CAACG,IAAI,CAAC,GAAG,CAAE,MAAK,CAAC;AAE1D,eAAe,SAASC,iBAAiBA,CACvCC,YAAqC,EACrC,CAAC,GAAGC,QAAQ,CAAwC,EACpDC,UAAsB,EACtBC,kBAA8D,EACF;EAC5D,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ACe,KAAK,CAAC,EAAE;UAC3B;UACAH,OAAO,IAAIf,UAAU,CAACuB,GAAG,EAAErB,KAAK,CAACgB,KAAK,CAAC,CAAC;QAC1C,CAAC,MAAM;UACL;UACAH,OAAO,IAAIf,UAAU,CAACuB,GAAG,EAAEL,KAAK,CAAC;QACnC;QAEAL,qBAAqB,CAACoC,IAAI,CAAC;UACzBC,QAAQ,EAAE3B,GAAG;UACbE,MAAM,EAAEV,OAAO,CAACU,MAAM,GAAGD;QAC3B,CAAC,CAAC;MACJ;IACF;EACF;EAEA,MAAM2B,KAAK,GAAG1C,YAAY,CAAC2C,YAAY,CACrCzC,UAAU,EACVI,OAAO,EACPN,YAAY,CAAC4C,QACf,CAAC;;EAED;EACA,IAAI,CAACvC,YAAY,IAAI,CAACC,OAAO,CAACuC,QAAQ,CAAC,SAAS,CAAC,EAAE;IACjD,OAAO,IAAI;EACb;;EAEA;EACA,OAAO,CAACH,KAAK,EAAEtC,qBAAqB,CAAC;AACvC"}
1
+ {"version":3,"file":"templateProcessor.js","names":["hasEvalMeta","ValueType","getVariableName","stripLines","throwIfInvalid","toCSS","isCSSable","units","unitRegex","RegExp","join","templateProcessor","tagProcessor","template","valueCache","variableNameConfig","sourceMapReplacements","isReferenced","cssText","item","shift","value","cooked","ex","end","start","loc","beforeLength","length","next","line","column","get","name","kind","FUNCTION","matches","match","unit","varId","addInterpolation","source","substring","e","Error","buildCodeFrameError","message","isValidValue","bind","undefined","__wyw_meta","className","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":"AAAA;AACA;AACA;AACA;AACA;;AAKA,SAASA,WAAW,EAAEC,SAAS,QAAQ,mBAAmB;AAK1D,SAASC,eAAe,QAAQ,mBAAmB;AACnD,OAAOC,UAAU,MAAM,cAAc;AACrC,OAAOC,cAAc,MAAM,kBAAkB;AAC7C,OAAOC,KAAK,IAAIC,SAAS,QAAQ,SAAS;AAE1C,SAASC,KAAK,QAAQ,SAAS;;AAE/B;AACA,MAAMC,SAAS,GAAG,IAAIC,MAAM,CAAE,OAAMF,KAAK,CAACG,IAAI,CAAC,GAAG,CAAE,mBAAkB,CAAC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AC,EAAE;UACtB;UACA;UACAH,OAAO,IAAK,IAAGG,KAAK,CAAC6B,UAAU,CAACC,SAAU,EAAC;QAC7C,CAAC,MAAM,IAAI7C,SAAS,CAACe,KAAK,CAAC,EAAE;UAC3B;UACAH,OAAO,IAAIf,UAAU,CAACuB,GAAG,EAAErB,KAAK,CAACgB,KAAK,CAAC,CAAC;QAC1C,CAAC,MAAM;UACL;UACAH,OAAO,IAAIf,UAAU,CAACuB,GAAG,EAAEL,KAAK,CAAC;QACnC;QAEAL,qBAAqB,CAACoC,IAAI,CAAC;UACzBC,QAAQ,EAAE3B,GAAG;UACbE,MAAM,EAAEV,OAAO,CAACU,MAAM,GAAGD;QAC3B,CAAC,CAAC;MACJ;IACF;EACF;EAEA,MAAM2B,KAAK,GAAG1C,YAAY,CAAC2C,YAAY,CACrCzC,UAAU,EACVI,OAAO,EACPN,YAAY,CAAC4C,QACf,CAAC;;EAED;EACA,IAAI,CAACvC,YAAY,IAAI,CAACC,OAAO,CAACuC,QAAQ,CAAC,SAAS,CAAC,EAAE;IACjD,OAAO,IAAI;EACb;;EAEA;EACA,OAAO,CAACH,KAAK,EAAEtC,qBAAqB,CAAC;AACvC"}
@@ -19,8 +19,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
19
  * It uses CSS code from template literals and evaluated values of lazy dependencies stored in ValueCache.
20
20
  */
21
21
 
22
- // Match any valid CSS units followed by a separator such as ;, newline etc.
23
- const unitRegex = new RegExp(`^(?:${_units.units.join('|')})\\b`);
22
+ // Match any valid CSS unit not immediately followed by an alphanumeric character or underscore.
23
+ const unitRegex = new RegExp(`^(?:${_units.units.join('|')})(?![a-zA-Z0-9_])`);
24
24
  function templateProcessor(tagProcessor, [...template], valueCache, variableNameConfig) {
25
25
  const sourceMapReplacements = [];
26
26
  // Check if the variable is referenced anywhere for basic DCE
@@ -1 +1 @@
1
- {"version":3,"file":"templateProcessor.js","names":["_shared","require","_getVariableName","_stripLines","_interopRequireDefault","_throwIfInvalid","_toCSS","_interopRequireWildcard","_units","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","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 units followed by a separator such as ;, newline etc.\nconst unitRegex = new RegExp(`^(?:${units.join('|')})\\\\b`);\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,SAAAQ,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAA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mBAAU,EAACjC,GAAG,EAAE,IAAAkC,cAAK,EAACvC,KAAK,CAAC,CAAC;QAC1C,CAAC,MAAM;UACL;UACAH,OAAO,IAAI,IAAAyC,mBAAU,EAACjC,GAAG,EAAEL,KAAK,CAAC;QACnC;QAEAL,qBAAqB,CAAC6C,IAAI,CAAC;UACzBC,QAAQ,EAAEpC,GAAG;UACbE,MAAM,EAAEV,OAAO,CAACU,MAAM,GAAGD;QAC3B,CAAC,CAAC;MACJ;IACF;EACF;EAEA,MAAMoC,KAAK,GAAGnD,YAAY,CAACoD,YAAY,CACrClD,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"}
1
+ {"version":3,"file":"templateProcessor.js","names":["_shared","require","_getVariableName","_stripLines","_interopRequireDefault","_throwIfInvalid","_toCSS","_interopRequireWildcard","_units","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","obj","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,M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AqB,CAAC;AACvC"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@wyw-in-js/processor-utils",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "dependencies": {
5
5
  "@babel/generator": "^7.23.5",
6
- "@wyw-in-js/shared": "0.7.0"
6
+ "@wyw-in-js/shared": "0.8.1"
7
7
  },
8
8
  "devDependencies": {
9
9
  "@babel/types": "^7.23.5",
@@ -11,10 +11,10 @@
11
11
  "@types/babel__generator": "^7.6.7",
12
12
  "@types/node": "^16.18.55",
13
13
  "typescript": "^5.2.2",
14
- "@wyw-in-js/babel-config": "0.7.0",
15
- "@wyw-in-js/eslint-config": "0.7.0",
16
- "@wyw-in-js/jest-preset": "0.7.0",
17
- "@wyw-in-js/ts-config": "0.7.0"
14
+ "@wyw-in-js/babel-config": "0.8.1",
15
+ "@wyw-in-js/eslint-config": "0.8.1",
16
+ "@wyw-in-js/jest-preset": "0.8.1",
17
+ "@wyw-in-js/ts-config": "0.8.1"
18
18
  },
19
19
  "engines": {
20
20
  "node": ">=16.0.0"
@@ -37,8 +37,8 @@ const stripLines_1 = __importDefault(require("./stripLines"));
37
37
  const throwIfInvalid_1 = __importDefault(require("./throwIfInvalid"));
38
38
  const toCSS_1 = __importStar(require("./toCSS"));
39
39
  const units_1 = require("./units");
40
- // Match any valid CSS units followed by a separator such as ;, newline etc.
41
- const unitRegex = new RegExp(`^(?:${units_1.units.join('|')})\\b`);
40
+ // Match any valid CSS unit not immediately followed by an alphanumeric character or underscore.
41
+ const unitRegex = new RegExp(`^(?:${units_1.units.join('|')})(?![a-zA-Z0-9_])`);
42
42
  function templateProcessor(tagProcessor, [...template], valueCache, variableNameConfig) {
43
43
  const sourceMapReplacements = [];
44
44
  // Check if the variable is referenced anywhere for basic DCE