@wyw-in-js/processor-utils 1.0.5 → 1.1.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.
@@ -2,6 +2,7 @@
2
2
 
3
3
  import generator from '@babel/generator';
4
4
  import { hasEvalMeta } from '@wyw-in-js/shared';
5
+ import { createProcessorDiagnosticArtifact } from './diagnostics';
5
6
  import getClassNameAndSlug from './utils/getClassNameAndSlug';
6
7
  import { isCSSable } from './utils/toCSS';
7
8
  import { validateParams } from './utils/validateParams';
@@ -40,6 +41,13 @@ export class BaseProcessor {
40
41
  * whereas `styled` tag will be replaced with an object with metadata.
41
42
  */
42
43
 
44
+ addDiagnostic(diagnostic) {
45
+ this.artifacts.push(createProcessorDiagnosticArtifact({
46
+ ...diagnostic,
47
+ end: diagnostic.end ?? this.location?.end ?? null,
48
+ start: diagnostic.start ?? this.location?.start ?? null
49
+ }));
50
+ }
43
51
  isValidValue(value) {
44
52
  return typeof value === 'function' || isCSSable(value) || hasEvalMeta(value);
45
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BaseProcessor.js","names":["generator","hasEvalMeta","getClassNameAndSlug","isCSSable","validateParams","BaseProcessor","SKIP","Symbol","artifacts","dependencies","interpolations","constructor","params","tagSource","astService","location","replacer","displayName","isReferenced","idx","options","context","className","slug","callee","isValidValue","value","toString","tagSourceCode","type","name","code"],"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 type { IInterpolation, Params, Value, ValueCache } 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 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":"AAAA;;AAEA,OAAOA,SAAS,MAAM,kBAAkB;AASxC,SAASC,WAAW,QAAQ,mBAAmB;AAG/C,OAAOC,mBAAmB,MAAM,6BAA6B;AAC7D,SAASC,SAAS,QAAQ,eAAe;AAEzC,SAASC,cAAc,QAAQ,wBAAwB;AAcvD,OAAO,MAAeC,aAAa,CAAC;EAClC,OAAcC,IAAI,GAAGC,MAAM,CAAC,MAAM,CAAC;EAEnBC,SAAS,GAAe,EAAE;EAI1BC,YAAY,GAAsB,EAAE;EAE7CC,cAAc,GAAqB,EAAE;EAUrCC,WAAWA,CAChBC,MAAc,EACPC,SAAoB,EACRC,UAOlB,EACeC,QAA+B,EAC5BC,QAGV,EACOC,WAAmB,EACnBC,YAAqB,EAClBC,GAAW,EACXC,OAAiB,EACjBC,OAAqB,EACxC;IAAA,KAnBOR,SAAoB,GAApBA,SAAoB;IAAA,KACRC,UAOlB,GAPkBA,UAOlB;IAAA,KACeC,QAA+B,GAA/BA,QAA+B;IAAA,KAC5BC,QAGV,GAHUA,QAGV;IAAA,KACOC,WAAmB,GAAnBA,WAAmB;IAAA,KACnBC,YAAqB,GAArBA,YAAqB;IAAA,KAClBC,GAAW,GAAXA,GAAW;IAAA,KACXC,OAAiB,GAAjBA,OAAiB;IAAA,KACjBC,OAAqB,GAArBA,OAAqB;IAExCjB,cAAc,CACZQ,MAAM,EACN,CAAC,QAAQ,CAAC,EACV,gDACF,CAAC;IAED,MAAM;MAAEU,SAAS;MAAEC;IAAK,CAAC,GAAGrB,mBAAmB,CAC7C,IAAI,CAACe,WAAW,EAChB,IAAI,CAACE,GAAG,EACR,IAAI,CAACC,OAAO,EACZ,IAAI,CAACC,OACP,CAAC;IAED,IAAI,CAACC,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,IAAI,GAAGA,IAAI;IAEhB,CAAC,GAAG,IAAI,CAACC,MAAM,CAAC,CAAC,GAAGZ,MAAM;EAC5B;;EAEA;AACF;AACA;;EAGE;AACF;AACA;AACA;AACA;;EAGSa,YAAYA,CAACC,KAAc,EAAkB;IAClD,OACE,OAAOA,KAAK,KAAK,UAAU,IAAIvB,SAAS,CAACuB,KAAK,CAAC,IAAIzB,WAAW,CAACyB,KAAK,CAAC;EAEzE;EAEOC,QAAQA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACC,aAAa,CAAC,CAAC;EAC7B;EAEUA,aAAaA,CAAA,EAAW;IAChC,IAAI,IAAI,CAACJ,MAAM,CAACK,IAAI,KAAK,YAAY,EAAE;MACrC,OAAO,IAAI,CAACL,MAAM,CAACM,IAAI;IACzB;IAEA,OAAO9B,SAAS,CAAC,IAAI,CAACwB,MAAM,CAAC,CAACO,IAAI;EACpC;;EAIA;AACF;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AAEA","ignoreList":[]}
1
+ {"version":3,"file":"BaseProcessor.js","names":["generator","hasEvalMeta","createProcessorDiagnosticArtifact","getClassNameAndSlug","isCSSable","validateParams","BaseProcessor","SKIP","Symbol","artifacts","dependencies","interpolations","constructor","params","tagSource","astService","location","replacer","displayName","isReferenced","idx","options","context","className","slug","callee","addDiagnostic","diagnostic","push","end","start","isValidValue","value","toString","tagSourceCode","type","name","code"],"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":"AAAA;;AAEA,OAAOA,SAAS,MAAM,kBAAkB;AASxC,SAASC,WAAW,QAAQ,mBAAmB;AAE/C,SAASC,iCAAiC,QAAQ,eAAe;AAQjE,OAAOC,mBAAmB,MAAM,6BAA6B;AAC7D,SAASC,SAAS,QAAQ,eAAe;AAEzC,SAASC,cAAc,QAAQ,wBAAwB;AAcvD,OAAO,MAAeC,aAAa,CAAC;EAClC,OAAcC,IAAI,GAAGC,MAAM,CAAC,MAAM,CAAC;EAEnBC,SAAS,GAAe,EAAE;EAI1BC,YAAY,GAAsB,EAAE;EAE7CC,cAAc,GAAqB,EAAE;EAUrCC,WAAWA,CAChBC,MAAc,EACPC,SAAoB,EACRC,UAOlB,EACeC,QAA+B,EAC5BC,QAGV,EACOC,WAAmB,EACnBC,YAAqB,EAClBC,GAAW,EACXC,OAAiB,EACjBC,OAAqB,EACxC;IAAA,KAnBOR,SAAoB,GAApBA,S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;EAC7B;EAEUA,aAAaA,CAAA,EAAW;IAChC,IAAI,IAAI,CAACT,MAAM,CAACU,IAAI,KAAK,YAAY,EAAE;MACrC,OAAO,IAAI,CAACV,MAAM,CAACW,IAAI;IACzB;IAEA,OAAOpC,SAAS,CAAC,IAAI,CAACyB,MAAM,CAAC,CAACY,IAAI;EACpC;;EAIA;AACF;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AAEA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ export const PROCESSOR_DIAGNOSTIC_ARTIFACT = 'wyw-in-js:diagnostic';
2
+ export const createProcessorDiagnosticArtifact = diagnostic => [PROCESSOR_DIAGNOSTIC_ARTIFACT, diagnostic];
3
+ export const isProcessorDiagnosticArtifact = artifact => artifact[0] === PROCESSOR_DIAGNOSTIC_ARTIFACT;
4
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","names":["PROCESSOR_DIAGNOSTIC_ARTIFACT","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":"AAIA,OAAO,MAAMA,6BAA6B,GAAG,sBAA+B;AAO5E,OAAO,MAAMC,iCAAiC,GAC5CC,UAA+B,IACC,CAACF,6BAA6B,EAAEE,UAAU,CAAC;AAE7E,OAAO,MAAMC,6BAA6B,GACxCC,QAAkB,IAElBA,QAAQ,CAAC,CAAC,CAAC,KAAKJ,6BAA6B","ignoreList":[]}
package/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { BaseProcessor } from './BaseProcessor';
2
+ export { createProcessorDiagnosticArtifact, isProcessorDiagnosticArtifact, PROCESSOR_DIAGNOSTIC_ARTIFACT } from './diagnostics';
2
3
  export * from './types';
3
4
  export { buildSlug } from './utils/buildSlug';
4
5
  export { isValidParams, validateParams } from './utils/validateParams';
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["BaseProcessor","buildSlug","isValidParams","validateParams","TaggedTemplateProcessor","toValidCSSIdentifier"],"sources":["../src/index.ts"],"sourcesContent":["export { BaseProcessor } from './BaseProcessor';\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,SAASA,aAAa,QAAQ,iBAAiB;AAO/C,cAAc,SAAS;AACvB,SAASC,SAAS,QAAQ,mBAAmB;AAE7C,SAASC,aAAa,EAAEC,cAAc,QAAQ,wBAAwB;AAEtE,SAASC,uBAAuB,QAAQ,2BAA2B;AACnE,SAASC,oBAAoB,QAAQ,8BAA8B","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["BaseProcessor","createProcessorDiagnosticArtifact","isProcessorDiagnosticArtifact","PROCESSOR_DIAGNOSTIC_ARTIFACT","buildSlug","isValidParams","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,SAASA,aAAa,QAAQ,iBAAiB;AAC/C,SACEC,iCAAiC,EACjCC,6BAA6B,EAC7BC,6BAA6B,QACxB,eAAe;AAQtB,cAAc,SAAS;AACvB,SAASC,SAAS,QAAQ,mBAAmB;AAE7C,SAASC,aAAa,EAAEC,cAAc,QAAQ,wBAAwB;AAEtE,SAASC,uBAAuB,QAAQ,2BAA2B;AACnE,SAASC,oBAAoB,QAAQ,8BAA8B","ignoreList":[]}
package/esm/types.js.map CHANGED
@@ -1 +1 @@
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 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
+ {"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":[]}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.BaseProcessor = void 0;
7
7
  var _generator = _interopRequireDefault(require("@babel/generator"));
8
8
  var _shared = require("@wyw-in-js/shared");
9
+ var _diagnostics = require("./diagnostics");
9
10
  var _getClassNameAndSlug = _interopRequireDefault(require("./utils/getClassNameAndSlug"));
10
11
  var _toCSS = require("./utils/toCSS");
11
12
  var _validateParams = require("./utils/validateParams");
@@ -47,6 +48,14 @@ class BaseProcessor {
47
48
  * whereas `styled` tag will be replaced with an object with metadata.
48
49
  */
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
+ }
50
59
  isValidValue(value) {
51
60
  return typeof value === 'function' || (0, _toCSS.isCSSable)(value) || (0, _shared.hasEvalMeta)(value);
52
61
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BaseProcessor.js","names":["_generator","_interopRequireDefault","require","_shared","_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","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 type { IInterpolation, Params, Value, ValueCache } 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 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;AAGA,IAAAE,oBAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,eAAA,GAAAJ,OAAA;AAAwD,SAAAD,uBAAAM,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAjBxD;;AA+BO,MAAeG,aAAa,CAAC;EAClC,OAAcC,IAAI,GAAGC,MAAM,CAAC,MAAM,CAAC;EAEnBC,SAAS,GAAe,EAAE;EAI1BC,YAAY,GAAsB,EAAE;EAE7CC,cAAc,GAAqB,EAAE;EAUrCC,WAAWA,CAChBC,MAAc,EACPC,SAAoB,EACRC,UAOlB,EACeC,QAA+B,EAC5BC,QAGV,EACOC,WAAmB,EACnBC,YAAqB,EAClBC,GAAW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AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AAEA;AAACC,OAAA,CAAAhC,aAAA,GAAAA,aAAA","ignoreList":[]}
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,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,eAAA,GAAAL,OAAA;AAAwD,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAxBxD;;AAsCO,MAAeG,aAAa,CAAC;EAClC,OAAcC,IAAI,GAAGC,MAAM,CAAC,MAAM,CAAC;EAEnBC,SAAS,GAAe,EAAE;EAI1BC,YAAY,GAAsB,EAAE;EAE7CC,cAAc,GAAqB,EAAE;EAUrCC,WAAWA,CAChBC,MAAc,EACPC,SAAoB,EACRC,UAOlB,EACeC,QAA+B,EAC5BC,QAGV,EACOC,WAAmB,EACnBC,YAAqB,EAClBC,GAAW,EACXC,OAAiB,EACjBC,OAAqB,EACxC;IAAA,KAnBOR,SAAoB,GAApBA,SAAoB;IAAA,KACRC,UAOlB,GAPkBA,UAOlB;IAAA,KACeC,QAA+B,GAA/BA,QAA+B;IAAA,KAC5BC,QAGV,GAHUA,QAGV;IAAA,KACOC,WAAmB,GAAnBA,WAAmB;IAAA,KACnBC,YAAqB,GAArBA,YAAqB;IAAA,KAClBC,GAAW,GAAXA,GAAW;IAAA,KACXC,OAAiB,GAAjBA,OAAiB;IAAA,KACjBC,OAAqB,GAArBA,OAAqB;IAExC,IAAAC,8BAAc,EACZV,MAAM,EACN,CAAC,QAAQ,CAAC,EACV,gDACF,CAAC;IAED,MAAM;MAAEW,SAAS;MAAEC;IAAK,CAAC,GAAG,IAAAC,4BAAmB,EAC7C,IAA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IAAI,KAAK,YAAY,EAAE;MACrC,OAAO,IAAI,CAACnB,MAAM,CAACoB,IAAI;IACzB;IAEA,OAAO,IAAAC,kBAAS,EAAC,IAAI,CAACrB,MAAM,CAAC,CAACsB,IAAI;EACpC;;EAIA;AACF;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AAEA;AAACC,OAAA,CAAA5C,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -0,0 +1,12 @@
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
@@ -0,0 +1 @@
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 CHANGED
@@ -5,6 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  var _exportNames = {
7
7
  BaseProcessor: true,
8
+ createProcessorDiagnosticArtifact: true,
9
+ isProcessorDiagnosticArtifact: true,
10
+ PROCESSOR_DIAGNOSTIC_ARTIFACT: true,
8
11
  buildSlug: true,
9
12
  isValidParams: true,
10
13
  validateParams: true,
@@ -17,6 +20,12 @@ Object.defineProperty(exports, "BaseProcessor", {
17
20
  return _BaseProcessor.BaseProcessor;
18
21
  }
19
22
  });
23
+ Object.defineProperty(exports, "PROCESSOR_DIAGNOSTIC_ARTIFACT", {
24
+ enumerable: true,
25
+ get: function () {
26
+ return _diagnostics.PROCESSOR_DIAGNOSTIC_ARTIFACT;
27
+ }
28
+ });
20
29
  Object.defineProperty(exports, "TaggedTemplateProcessor", {
21
30
  enumerable: true,
22
31
  get: function () {
@@ -29,6 +38,18 @@ Object.defineProperty(exports, "buildSlug", {
29
38
  return _buildSlug.buildSlug;
30
39
  }
31
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
+ });
32
53
  Object.defineProperty(exports, "isValidParams", {
33
54
  enumerable: true,
34
55
  get: function () {
@@ -48,6 +69,7 @@ Object.defineProperty(exports, "validateParams", {
48
69
  }
49
70
  });
50
71
  var _BaseProcessor = require("./BaseProcessor");
72
+ var _diagnostics = require("./diagnostics");
51
73
  var _types = require("./types");
52
74
  Object.keys(_types).forEach(function (key) {
53
75
  if (key === "default" || key === "__esModule") return;
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_BaseProcessor","require","_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 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;AAOA,IAAAC,MAAA,GAAAD,OAAA;AAAAE,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,GAAAd,OAAA;AAEA,IAAAe,eAAA,GAAAf,OAAA;AAEA,IAAAgB,wBAAA,GAAAhB,OAAA;AACA,IAAAiB,qBAAA,GAAAjB,OAAA","ignoreList":[]}
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.map CHANGED
@@ -1 +1 @@
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 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
+ {"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":[]}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@wyw-in-js/processor-utils",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "dependencies": {
5
5
  "@babel/generator": "^7.23.5",
6
- "@wyw-in-js/shared": "1.0.5"
6
+ "@wyw-in-js/shared": "1.1.0"
7
7
  },
8
8
  "devDependencies": {
9
9
  "@babel/types": "^7.23.5",
@@ -1,7 +1,7 @@
1
1
  import type { NodePath, types as t } from '@babel/core';
2
2
  import type { Expression, Identifier, SourceLocation, MemberExpression } from '@babel/types';
3
3
  import type { Artifact, ExpressionValue } from '@wyw-in-js/shared';
4
- import type { IInterpolation, Params, Value, ValueCache } from './types';
4
+ import type { IInterpolation, Params, ProcessorDiagnostic, Value, ValueCache } from './types';
5
5
  import type { IFileContext, IOptions } from './utils/types';
6
6
  export { Expression };
7
7
  export type ProcessorParams = ConstructorParameters<typeof BaseProcessor>;
@@ -45,6 +45,7 @@ export declare abstract class BaseProcessor {
45
45
  * whereas `styled` tag will be replaced with an object with metadata.
46
46
  */
47
47
  abstract get value(): Expression;
48
+ addDiagnostic(diagnostic: ProcessorDiagnostic): void;
48
49
  isValidValue(value: unknown): value is Value;
49
50
  toString(): string;
50
51
  protected tagSourceCode(): string;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BaseProcessor = void 0;
7
7
  const generator_1 = __importDefault(require("@babel/generator"));
8
8
  const shared_1 = require("@wyw-in-js/shared");
9
+ const diagnostics_1 = require("./diagnostics");
9
10
  const getClassNameAndSlug_1 = __importDefault(require("./utils/getClassNameAndSlug"));
10
11
  const toCSS_1 = require("./utils/toCSS");
11
12
  const validateParams_1 = require("./utils/validateParams");
@@ -43,6 +44,13 @@ class BaseProcessor {
43
44
  this.slug = slug;
44
45
  [[, this.callee]] = params;
45
46
  }
47
+ addDiagnostic(diagnostic) {
48
+ this.artifacts.push((0, diagnostics_1.createProcessorDiagnosticArtifact)({
49
+ ...diagnostic,
50
+ end: diagnostic.end ?? this.location?.end ?? null,
51
+ start: diagnostic.start ?? this.location?.start ?? null,
52
+ }));
53
+ }
46
54
  isValidValue(value) {
47
55
  return (typeof value === 'function' || (0, toCSS_1.isCSSable)(value) || (0, shared_1.hasEvalMeta)(value));
48
56
  }
@@ -0,0 +1,9 @@
1
+ import type { Artifact } from '@wyw-in-js/shared';
2
+ import type { ProcessorDiagnostic } from './types';
3
+ export declare const PROCESSOR_DIAGNOSTIC_ARTIFACT: "wyw-in-js:diagnostic";
4
+ export type ProcessorDiagnosticArtifact = [
5
+ name: typeof PROCESSOR_DIAGNOSTIC_ARTIFACT,
6
+ data: ProcessorDiagnostic
7
+ ];
8
+ export declare const createProcessorDiagnosticArtifact: (diagnostic: ProcessorDiagnostic) => ProcessorDiagnosticArtifact;
9
+ export declare const isProcessorDiagnosticArtifact: (artifact: Artifact) => artifact is ProcessorDiagnosticArtifact;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isProcessorDiagnosticArtifact = exports.createProcessorDiagnosticArtifact = exports.PROCESSOR_DIAGNOSTIC_ARTIFACT = void 0;
4
+ exports.PROCESSOR_DIAGNOSTIC_ARTIFACT = 'wyw-in-js:diagnostic';
5
+ const createProcessorDiagnosticArtifact = (diagnostic) => [exports.PROCESSOR_DIAGNOSTIC_ARTIFACT, diagnostic];
6
+ exports.createProcessorDiagnosticArtifact = createProcessorDiagnosticArtifact;
7
+ const isProcessorDiagnosticArtifact = (artifact) => artifact[0] === exports.PROCESSOR_DIAGNOSTIC_ARTIFACT;
8
+ exports.isProcessorDiagnosticArtifact = isProcessorDiagnosticArtifact;
package/types/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export { BaseProcessor } from './BaseProcessor';
2
+ export { createProcessorDiagnosticArtifact, isProcessorDiagnosticArtifact, PROCESSOR_DIAGNOSTIC_ARTIFACT, } from './diagnostics';
3
+ export type { ProcessorDiagnosticArtifact } from './diagnostics';
2
4
  export type { Expression, TagSource, ProcessorParams, TailProcessorParams, } from './BaseProcessor';
3
5
  export * from './types';
4
6
  export { buildSlug } from './utils/buildSlug';
package/types/index.js CHANGED
@@ -14,9 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.toValidCSSIdentifier = exports.TaggedTemplateProcessor = exports.validateParams = exports.isValidParams = exports.buildSlug = exports.BaseProcessor = void 0;
17
+ exports.toValidCSSIdentifier = exports.TaggedTemplateProcessor = exports.validateParams = exports.isValidParams = exports.buildSlug = exports.PROCESSOR_DIAGNOSTIC_ARTIFACT = exports.isProcessorDiagnosticArtifact = exports.createProcessorDiagnosticArtifact = exports.BaseProcessor = void 0;
18
18
  var BaseProcessor_1 = require("./BaseProcessor");
19
19
  Object.defineProperty(exports, "BaseProcessor", { enumerable: true, get: function () { return BaseProcessor_1.BaseProcessor; } });
20
+ var diagnostics_1 = require("./diagnostics");
21
+ Object.defineProperty(exports, "createProcessorDiagnosticArtifact", { enumerable: true, get: function () { return diagnostics_1.createProcessorDiagnosticArtifact; } });
22
+ Object.defineProperty(exports, "isProcessorDiagnosticArtifact", { enumerable: true, get: function () { return diagnostics_1.isProcessorDiagnosticArtifact; } });
23
+ Object.defineProperty(exports, "PROCESSOR_DIAGNOSTIC_ARTIFACT", { enumerable: true, get: function () { return diagnostics_1.PROCESSOR_DIAGNOSTIC_ARTIFACT; } });
20
24
  __exportStar(require("./types"), exports);
21
25
  var buildSlug_1 = require("./utils/buildSlug");
22
26
  Object.defineProperty(exports, "buildSlug", { enumerable: true, get: function () { return buildSlug_1.buildSlug; } });
package/types/types.d.ts CHANGED
@@ -20,6 +20,14 @@ export interface IInterpolation {
20
20
  source: string;
21
21
  unit: string;
22
22
  }
23
+ export type ProcessorDiagnosticSeverity = 'error' | 'warning';
24
+ export type ProcessorDiagnostic = {
25
+ category: string;
26
+ end?: Location | null;
27
+ message: string;
28
+ severity: ProcessorDiagnosticSeverity;
29
+ start?: Location | null;
30
+ };
23
31
  export type Rules = Record<string, ICSSRule>;
24
32
  export type CalleeParam = readonly ['callee', Identifier | MemberExpression];
25
33
  export type CallParam = readonly ['call', ...ExpressionValue[]];