@wyw-in-js/processor-utils 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/BaseProcessor.js.map
CHANGED
|
@@ -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 { 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,\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,M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A,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"}
|
|
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,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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"}
|
package/lib/BaseProcessor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseProcessor.js","names":["_generator","_interopRequireDefault","require","_shared","_getClassNameAndSlug","_toCSS","_validateParams","obj","__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 { 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,\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,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;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,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,IAAI,CAACR,WAAW,EAChB,IAAI,CAACE,GAAG,EACR,IAAI,CAACC,OAAO,EACZ,IAAI,CAACC,OACP,CAAC;IAED,IAAI,CAACE,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,IAAI,GAAGA,IAAI;IAEhB,CAAC,GAAG,IAAI,CAACE,MAAM,CAAC,CAAC,GAAGd,MAAM;EAC5B;;EAEA;AACF;AACA;;EAGE;AACF;AACA;AACA;AACA;;EAGSe,YAAYA,CAACC,KAAc,EAAkB;IAClD,OACE,OAAOA,KAAK,KAAK,UAAU,IAAI,IAAAC,gBAAS,EAACD,KAAK,CAAC,IAAI,IAAAE,mBAAW,EAACF,KAAK,CAAC;EAEzE;EAEOG,QAAQA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACC,aAAa,CAAC,CAAC;EAC7B;EAEUA,aAAaA,CAAA,EAAW;IAChC,IAAI,IAAI,CAACN,MAAM,CAACO,IAAI,KAAK,YAAY,EAAE;MACrC,OAAO,IAAI,CAACP,MAAM,CAACQ,IAAI;IACzB;IAEA,OAAO,IAAAC,kBAAS,EAAC,IAAI,CAACT,MAAM,CAAC,CAACU,IAAI;EACpC;;EAIA;AACF;AACA;AACA;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;AACA;AAEA;AAACC,OAAA,CAAAhC,aAAA,GAAAA,aAAA"}
|
|
1
|
+
{"version":3,"file":"BaseProcessor.js","names":["_generator","_interopRequireDefault","require","_shared","_getClassNameAndSlug","_toCSS","_validateParams","obj","__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,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;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,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,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"name": "@wyw-in-js/processor-utils",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@babel/generator": "^7.23.5",
|
|
6
|
-
"@wyw-in-js/shared": "0.5.
|
|
6
|
+
"@wyw-in-js/shared": "0.5.2"
|
|
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.5.
|
|
15
|
-
"@wyw-in-js/eslint-config": "0.5.
|
|
16
|
-
"@wyw-in-js/jest-preset": "0.5.
|
|
17
|
-
"@wyw-in-js/ts-config": "0.5.
|
|
14
|
+
"@wyw-in-js/babel-config": "0.5.2",
|
|
15
|
+
"@wyw-in-js/eslint-config": "0.5.2",
|
|
16
|
+
"@wyw-in-js/jest-preset": "0.5.2",
|
|
17
|
+
"@wyw-in-js/ts-config": "0.5.2"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=16.0.0"
|
package/types/BaseProcessor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { types as t } from '@babel/core';
|
|
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
4
|
import type { IInterpolation, Params, Value, ValueCache } from './types';
|
|
@@ -17,7 +17,7 @@ export declare abstract class BaseProcessor {
|
|
|
17
17
|
addNamedImport: (name: string, source: string, nameHint?: string) => Identifier;
|
|
18
18
|
};
|
|
19
19
|
readonly location: SourceLocation | null;
|
|
20
|
-
protected readonly replacer: (replacement: Expression, isPure: boolean) => void;
|
|
20
|
+
protected readonly replacer: (replacement: Expression | ((tagPath: NodePath) => Expression), isPure: boolean) => void;
|
|
21
21
|
readonly displayName: string;
|
|
22
22
|
readonly isReferenced: boolean;
|
|
23
23
|
protected readonly idx: number;
|
|
@@ -34,7 +34,7 @@ export declare abstract class BaseProcessor {
|
|
|
34
34
|
constructor(params: Params, tagSource: TagSource, astService: typeof t & {
|
|
35
35
|
addDefaultImport: (source: string, nameHint?: string) => Identifier;
|
|
36
36
|
addNamedImport: (name: string, source: string, nameHint?: string) => Identifier;
|
|
37
|
-
}, location: SourceLocation | null, replacer: (replacement: Expression, isPure: boolean) => void, displayName: string, isReferenced: boolean, idx: number, options: IOptions, context: IFileContext);
|
|
37
|
+
}, location: SourceLocation | null, replacer: (replacement: Expression | ((tagPath: NodePath) => Expression), isPure: boolean) => void, displayName: string, isReferenced: boolean, idx: number, options: IOptions, context: IFileContext);
|
|
38
38
|
/**
|
|
39
39
|
* A replacement for tag referenced in a template literal.
|
|
40
40
|
*/
|