@wyw-in-js/transform 0.3.0 → 0.4.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.
- package/esm/index.js +1 -2
- package/esm/index.js.map +1 -1
- package/esm/plugins/collector.js +5 -11
- package/esm/plugins/collector.js.map +1 -1
- package/esm/plugins/preeval.js +11 -17
- package/esm/plugins/preeval.js.map +1 -1
- package/esm/transform/Entrypoint.js +2 -1
- package/esm/transform/Entrypoint.js.map +1 -1
- package/esm/transform/generators/createStylisPreprocessor.js +171 -51
- package/esm/transform/generators/createStylisPreprocessor.js.map +1 -1
- package/esm/utils/getTagProcessor.js +113 -51
- package/esm/utils/getTagProcessor.js.map +1 -1
- package/lib/index.js +7 -15
- package/lib/index.js.map +1 -1
- package/lib/plugins/collector.js +6 -12
- package/lib/plugins/collector.js.map +1 -1
- package/lib/plugins/preeval.js +12 -17
- package/lib/plugins/preeval.js.map +1 -1
- package/lib/transform/Entrypoint.js +2 -1
- package/lib/transform/Entrypoint.js.map +1 -1
- package/lib/transform/generators/createStylisPreprocessor.js +176 -51
- package/lib/transform/generators/createStylisPreprocessor.js.map +1 -1
- package/lib/utils/getTagProcessor.js +122 -53
- package/lib/utils/getTagProcessor.js.map +1 -1
- package/package.json +7 -7
- package/types/index.d.ts +1 -2
- package/types/index.js +2 -4
- package/types/plugins/collector.d.ts +5 -1
- package/types/plugins/collector.js +5 -10
- package/types/plugins/preeval.d.ts +3 -3
- package/types/plugins/preeval.js +11 -14
- package/types/transform/Entrypoint.js +4 -1
- package/types/transform/generators/createStylisPreprocessor.d.ts +4 -1
- package/types/transform/generators/createStylisPreprocessor.js +187 -59
- package/types/utils/getTagProcessor.d.ts +10 -3
- package/types/utils/getTagProcessor.js +108 -53
- package/esm/utils/processTemplateExpression.js +0 -11
- package/esm/utils/processTemplateExpression.js.map +0 -1
- package/lib/utils/processTemplateExpression.js +0 -18
- package/lib/utils/processTemplateExpression.js.map +0 -1
- package/types/utils/processTemplateExpression.d.ts +0 -5
- package/types/utils/processTemplateExpression.js +0 -17
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.applyProcessors = applyProcessors;
|
|
7
|
+
exports.getDefinedProcessors = getDefinedProcessors;
|
|
8
|
+
exports.getProcessorForImport = getProcessorForImport;
|
|
7
9
|
var _fs = require("fs");
|
|
8
10
|
var _path = require("path");
|
|
9
11
|
var _core = require("@babel/core");
|
|
@@ -76,53 +78,28 @@ function getProcessorFromFile(processorPath) {
|
|
|
76
78
|
}
|
|
77
79
|
return Processor;
|
|
78
80
|
}
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return [null, null, null];
|
|
85
|
-
}
|
|
81
|
+
function getProcessorForImport({
|
|
82
|
+
imported,
|
|
83
|
+
source
|
|
84
|
+
}, filename, options) {
|
|
85
|
+
var _options$tagResolver;
|
|
86
86
|
const tagResolver = (_options$tagResolver = options.tagResolver) !== null && _options$tagResolver !== void 0 ? _options$tagResolver : () => null;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const {
|
|
91
|
-
local
|
|
92
|
-
} = i;
|
|
93
|
-
if (local === path) {
|
|
94
|
-
return [i, null];
|
|
95
|
-
}
|
|
96
|
-
if (!local.isIdentifier()) {
|
|
97
|
-
if (path.isDescendant(local)) {
|
|
98
|
-
return [i, local];
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
const binding = local.scope.getBinding(local.node.name);
|
|
103
|
-
if (pathBinding === binding) {
|
|
104
|
-
return [i, path];
|
|
105
|
-
}
|
|
106
|
-
return null;
|
|
107
|
-
}).filter(_isNotNull.isNotNull).filter(i => i[1] === null || i[1].isExpression());
|
|
108
|
-
if (relatedImports.length === 0) {
|
|
109
|
-
return [null, null, null];
|
|
110
|
-
}
|
|
111
|
-
const [Processor = null, tagSource = null, tagPath = null] = (_relatedImports$map$f = relatedImports.map(([{
|
|
87
|
+
const customFile = tagResolver(source, imported);
|
|
88
|
+
const processor = customFile ? getProcessorFromFile(customFile) : getProcessorFromPackage(source, imported, filename);
|
|
89
|
+
return [processor, {
|
|
112
90
|
imported,
|
|
113
91
|
source
|
|
114
|
-
}
|
|
115
|
-
const customFile = tagResolver(source, imported);
|
|
116
|
-
const processor = customFile ? getProcessorFromFile(customFile) : getProcessorFromPackage(source, imported, filename);
|
|
117
|
-
return [processor, {
|
|
118
|
-
imported,
|
|
119
|
-
source
|
|
120
|
-
}, p];
|
|
121
|
-
}).find(([proc]) => proc)) !== null && _relatedImports$map$f !== void 0 ? _relatedImports$map$f : [];
|
|
122
|
-
return Processor === null || tagSource === null || tagPath === null ? [null, null, null] : [Processor, tagSource, tagPath];
|
|
92
|
+
}];
|
|
123
93
|
}
|
|
124
|
-
function getBuilderForIdentifier(path, imports,
|
|
125
|
-
|
|
94
|
+
function getBuilderForIdentifier(definedProcessor, path, imports, options) {
|
|
95
|
+
var _tagPath$parentPath;
|
|
96
|
+
const [Processor, tagSource] = definedProcessor;
|
|
97
|
+
let tagPath = path;
|
|
98
|
+
if ((_tagPath$parentPath = tagPath.parentPath) !== null && _tagPath$parentPath !== void 0 && _tagPath$parentPath.isMemberExpression({
|
|
99
|
+
property: tagPath.node
|
|
100
|
+
})) {
|
|
101
|
+
tagPath = tagPath.parentPath;
|
|
102
|
+
}
|
|
126
103
|
if (!Processor || !tagSource || !tagPath) {
|
|
127
104
|
return null;
|
|
128
105
|
}
|
|
@@ -196,8 +173,7 @@ function getBuilderForIdentifier(path, imports, filename, options) {
|
|
|
196
173
|
}
|
|
197
174
|
});
|
|
198
175
|
};
|
|
199
|
-
const
|
|
200
|
-
..._core.types,
|
|
176
|
+
const importHelpers = {
|
|
201
177
|
addDefaultImport: (importedSource, nameHint) => (0, _helperModuleImports.addDefault)(path, importedSource, {
|
|
202
178
|
nameHint
|
|
203
179
|
}),
|
|
@@ -205,6 +181,14 @@ function getBuilderForIdentifier(path, imports, filename, options) {
|
|
|
205
181
|
nameHint
|
|
206
182
|
})
|
|
207
183
|
};
|
|
184
|
+
const astService = new Proxy(_core.types, {
|
|
185
|
+
get(target, prop, receiver) {
|
|
186
|
+
if (prop in importHelpers) {
|
|
187
|
+
return importHelpers[prop];
|
|
188
|
+
}
|
|
189
|
+
return Reflect.get(target, prop, receiver);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
208
192
|
return (...args) => {
|
|
209
193
|
var _tagPath$node$loc;
|
|
210
194
|
return new Processor(params, tagSource, astService, (_tagPath$node$loc = tagPath.node.loc) !== null && _tagPath$node$loc !== void 0 ? _tagPath$node$loc : null, replacer, ...args);
|
|
@@ -281,16 +265,44 @@ const getNextIndex = state => {
|
|
|
281
265
|
counters.set(state, counter + 1);
|
|
282
266
|
return counter;
|
|
283
267
|
};
|
|
284
|
-
function
|
|
268
|
+
function getDefinedProcessors(imports, path, filename, options) {
|
|
269
|
+
const cache = (0, _traversalCache.getTraversalCache)(path, 'getDefinedProcessors');
|
|
270
|
+
if (!cache.has(path)) {
|
|
271
|
+
const defined = new Map();
|
|
272
|
+
imports.forEach(i => {
|
|
273
|
+
const [processor, tagSource] = getProcessorForImport(i, filename, options);
|
|
274
|
+
const {
|
|
275
|
+
local
|
|
276
|
+
} = i;
|
|
277
|
+
if (!processor) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
let name = null;
|
|
281
|
+
if (local.isIdentifier()) {
|
|
282
|
+
name = local.node.name;
|
|
283
|
+
}
|
|
284
|
+
if (name === null && local.isMemberExpression()) {
|
|
285
|
+
const property = local.get('property');
|
|
286
|
+
const object = local.get('object');
|
|
287
|
+
if (property.isIdentifier() && object.isIdentifier()) {
|
|
288
|
+
name = `${object.node.name}.${property.node.name}`;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (name === null) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
defined.set(name, [processor, tagSource]);
|
|
295
|
+
});
|
|
296
|
+
cache.set(path, defined);
|
|
297
|
+
}
|
|
298
|
+
return cache.get(path);
|
|
299
|
+
}
|
|
300
|
+
function createProcessorInstance(definedProcessor, imports, path, fileContext, options) {
|
|
285
301
|
var _cache$get;
|
|
286
|
-
const cache = (0, _traversalCache.getTraversalCache)(path, '
|
|
302
|
+
const cache = (0, _traversalCache.getTraversalCache)(path, 'createProcessorInstance');
|
|
287
303
|
if (!cache.has(path.node)) {
|
|
288
|
-
const root = path.scope.getProgramParent().path;
|
|
289
|
-
const {
|
|
290
|
-
imports
|
|
291
|
-
} = (0, _collectExportsAndImports.collectExportsAndImports)(root);
|
|
292
304
|
try {
|
|
293
|
-
const builder = getBuilderForIdentifier(path, imports
|
|
305
|
+
const builder = getBuilderForIdentifier(definedProcessor, path, imports, options);
|
|
294
306
|
if (builder) {
|
|
295
307
|
// Increment the index of the style we're processing
|
|
296
308
|
// This is used for slug generation to prevent collision
|
|
@@ -315,4 +327,61 @@ function getTagProcessor(path, fileContext, options) {
|
|
|
315
327
|
}
|
|
316
328
|
return (_cache$get = cache.get(path.node)) !== null && _cache$get !== void 0 ? _cache$get : null;
|
|
317
329
|
}
|
|
330
|
+
function applyProcessors(path, fileContext, options, callback) {
|
|
331
|
+
const imports = (0, _collectExportsAndImports.collectExportsAndImports)(path).imports.filter(_collectExportsAndImports.explicitImport);
|
|
332
|
+
const definedProcessors = getDefinedProcessors(imports, path, fileContext.filename, options);
|
|
333
|
+
const usages = [];
|
|
334
|
+
definedProcessors.forEach((processor, idName) => {
|
|
335
|
+
var _path$scope$getBindin;
|
|
336
|
+
if (idName.includes('.')) {
|
|
337
|
+
// It's a member expression
|
|
338
|
+
const [object, property] = idName.split('.');
|
|
339
|
+
const objBinding = path.scope.getBinding(object);
|
|
340
|
+
if (!objBinding) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
objBinding.referencePaths.forEach(p => {
|
|
344
|
+
const parent = p.parentPath;
|
|
345
|
+
if (!(parent !== null && parent !== void 0 && parent.isMemberExpression())) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const identifier = parent.get('property');
|
|
349
|
+
if (identifier.isIdentifier({
|
|
350
|
+
name: property
|
|
351
|
+
})) {
|
|
352
|
+
usages.push({
|
|
353
|
+
identifier,
|
|
354
|
+
processor
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
(_path$scope$getBindin = path.scope.getBinding(idName)) === null || _path$scope$getBindin === void 0 || _path$scope$getBindin.referencePaths.forEach(identifier => {
|
|
361
|
+
if (identifier.isIdentifier()) {
|
|
362
|
+
usages.push({
|
|
363
|
+
identifier,
|
|
364
|
+
processor
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
// The same order, the same slugs
|
|
371
|
+
usages.sort((a, b) => {
|
|
372
|
+
var _a$identifier$node$st, _b$identifier$node$st;
|
|
373
|
+
return ((_a$identifier$node$st = a.identifier.node.start) !== null && _a$identifier$node$st !== void 0 ? _a$identifier$node$st : 0) - ((_b$identifier$node$st = b.identifier.node.start) !== null && _b$identifier$node$st !== void 0 ? _b$identifier$node$st : 0);
|
|
374
|
+
});
|
|
375
|
+
usages.forEach(usage => {
|
|
376
|
+
const definedProcessor = usage.processor;
|
|
377
|
+
if (!definedProcessor) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const instance = createProcessorInstance(definedProcessor, imports, usage.identifier, fileContext, options);
|
|
381
|
+
if (instance === null) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
callback(instance);
|
|
385
|
+
});
|
|
386
|
+
}
|
|
318
387
|
//# sourceMappingURL=getTagProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTagProcessor.js","names":["_fs","require","_path","_core","_helperModuleImports","_processorUtils","_shared","_collectExportsAndImports","_collectTemplateDependencies","_getSource","_isNotNull","_scopeHelpers","_traversalCache","last","arr","length","zip","arr1","arr2","result","i","push","buildCodeFrameError","path","message","Error","definedTagsCache","Map","getDefinedTagsFromPackage","pkgName","filename","_packageJSON$wywInJ","has","get","packageJSONPath","findPackageJSON","undefined","packageDir","dirname","packageJSON","JSON","parse","readFileSync","definedTags","tags","normalizedTags","Object","entries","reduce","acc","key","value","startsWith","join","resolve","paths","set","isValidProcessorClass","module","BaseProcessor","constructor","getProcessorFromPackage","packageName","tagName","processorPath","Processor","default","getProcessorFromFile","getProcessorForIdentifier","imports","options","_options$tagResolver","_relatedImports$map$f","pathBinding","scope","getBinding","node","name","tagResolver","relatedImports","map","local","isIdentifier","isDescendant","binding","filter","isNotNull","isExpression","tagSource","tagPath","imported","source","p","customFile","processor","find","proc","getBuilderForIdentifier","params","prev","current","parentPath","_current","_current2","_current3","_current4","isSequenceExpression","expressions","isCallExpression","callee","args","cookedArgs","arg","buildError","bind","type","getSource","extracted","extractExpression","evaluate","isMemberExpression","object","property","computed","isStringLiteral","isTaggedTemplateExpression","tag","quasis","expressionValues","collectTemplateDependencies","replacer","replacement","isPure","mutate","replaceWith","addComment","astService","t","addDefaultImport","importedSource","nameHint","addDefault","addNamedImport","addNamed","_tagPath$node$loc","loc","getDisplayName","idx","displayName","parent","findParent","isObjectProperty","isJSXOpeningElement","isVariableDeclarator","toString","keyPath","isJSXIdentifier","id","basename","test","replace","isTagReferenced","isReferenced","referencePaths","counters","WeakMap","getNextIndex","state","_counters$get","counter","getTagProcessor","fileContext","_cache$get","cache","getTraversalCache","root","getProgramParent","collectExportsAndImports","builder","explicitImport","e","SKIP"],"sources":["../../src/utils/getTagProcessor.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { basename, dirname, join } from 'path';\n\nimport { types as t } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport type { NodePath } from '@babel/traverse';\nimport type {\n Expression,\n SourceLocation,\n Identifier,\n MemberExpression,\n Program,\n} from '@babel/types';\n\nimport { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Param,\n Params,\n IFileContext,\n TagSource,\n} from '@wyw-in-js/processor-utils';\nimport { findPackageJSON } from '@wyw-in-js/shared';\nimport type { ExpressionValue, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { IImport } from './collectExportsAndImports';\nimport {\n collectExportsAndImports,\n explicitImport,\n} from './collectExportsAndImports';\nimport {\n collectTemplateDependencies,\n extractExpression,\n} from './collectTemplateDependencies';\nimport { getSource } from './getSource';\nimport { isNotNull } from './isNotNull';\nimport { mutate } from './scopeHelpers';\nimport { getTraversalCache } from './traversalCache';\n\ntype BuilderArgs = ConstructorParameters<typeof BaseProcessor> extends [\n Params,\n TagSource,\n typeof t,\n SourceLocation | null,\n (replacement: Expression, isPure: boolean) => void,\n ...infer T,\n]\n ? T\n : never;\n\ntype Builder = (...args: BuilderArgs) => BaseProcessor;\n\ntype ProcessorClass = new (\n ...args: ConstructorParameters<typeof BaseProcessor>\n) => BaseProcessor;\n\nconst last = <T>(arr: T[]): T | undefined => arr[arr.length - 1];\n\nfunction zip<T1, T2>(arr1: T1[], arr2: T2[]) {\n const result: (T1 | T2)[] = [];\n for (let i = 0; i < arr1.length; i++) {\n result.push(arr1[i]);\n if (arr2[i]) result.push(arr2[i]);\n }\n\n return result;\n}\n\nfunction buildCodeFrameError(path: NodePath, message: string): Error {\n try {\n return path.buildCodeFrameError(message);\n } catch {\n return new Error(message);\n }\n}\n\nconst definedTagsCache = new Map<string, Record<string, string> | undefined>();\nconst getDefinedTagsFromPackage = (\n pkgName: string,\n filename: string | null | undefined\n): Record<string, string> | undefined => {\n if (definedTagsCache.has(pkgName)) {\n return definedTagsCache.get(pkgName);\n }\n\n const packageJSONPath = findPackageJSON(pkgName, filename);\n if (!packageJSONPath) {\n return undefined;\n }\n\n const packageDir = dirname(packageJSONPath);\n const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'));\n const definedTags: Record<string, string> | undefined =\n packageJSON['wyw-in-js']?.tags;\n\n const normalizedTags = definedTags\n ? Object.entries(definedTags).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: value.startsWith('.')\n ? join(packageDir, value)\n : require.resolve(value, { paths: [packageDir] }),\n }),\n {} as Record<string, string>\n )\n : undefined;\n\n definedTagsCache.set(pkgName, normalizedTags);\n\n return normalizedTags;\n};\n\nfunction isValidProcessorClass(module: unknown): module is ProcessorClass {\n return module instanceof BaseProcessor.constructor;\n}\n\nfunction getProcessorFromPackage(\n packageName: string,\n tagName: string,\n filename: string | null | undefined\n): ProcessorClass | null {\n const definedTags = getDefinedTagsFromPackage(packageName, filename);\n const processorPath = definedTags?.[tagName];\n if (!processorPath) {\n return null;\n }\n\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nfunction getProcessorFromFile(processorPath: string): ProcessorClass | null {\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nfunction getProcessorForIdentifier(\n path: NodePath<Identifier>,\n imports: IImport[],\n filename: string | null | undefined,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >\n):\n | [ProcessorClass, TagSource, NodePath<Identifier | MemberExpression>]\n | [null, null, null] {\n const pathBinding = path.scope.getBinding(path.node.name);\n if (!pathBinding) {\n // It's not a binding, so it's not a tag\n return [null, null, null];\n }\n\n const tagResolver = options.tagResolver ?? (() => null);\n\n // FIXME: can be simplified\n const relatedImports = imports\n .map(\n (i): [IImport, NodePath<Identifier | MemberExpression> | null] | null => {\n const { local } = i;\n\n if (local === path) {\n return [i, null];\n }\n\n if (!local.isIdentifier()) {\n if (path.isDescendant(local)) {\n return [i, local];\n }\n\n return null;\n }\n\n const binding = local.scope.getBinding(local.node.name);\n if (pathBinding === binding) {\n return [i, path];\n }\n\n return null;\n }\n )\n .filter(isNotNull)\n .filter((i) => i[1] === null || i[1].isExpression());\n\n if (relatedImports.length === 0) {\n return [null, null, null];\n }\n\n const [Processor = null, tagSource = null, tagPath = null] =\n relatedImports\n .map(\n ([{ imported, source }, p]): [\n ProcessorClass | null,\n TagSource,\n NodePath<Identifier | MemberExpression> | null,\n ] => {\n const customFile = tagResolver(source, imported);\n const processor = customFile\n ? getProcessorFromFile(customFile)\n : getProcessorFromPackage(source, imported, filename);\n return [processor, { imported, source }, p];\n }\n )\n .find(([proc]) => proc) ?? [];\n\n return Processor === null || tagSource === null || tagPath === null\n ? [null, null, null]\n : [Processor, tagSource, tagPath];\n}\n\nfunction getBuilderForIdentifier(\n path: NodePath<Identifier>,\n imports: IImport[],\n filename: string | null | undefined,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >\n): Builder | null {\n const [Processor, tagSource, tagPath] = getProcessorForIdentifier(\n path,\n imports,\n filename,\n options\n );\n\n if (!Processor || !tagSource || !tagPath) {\n return null;\n }\n\n const params: Param[] = [['callee', tagPath.node]];\n let prev: NodePath = tagPath;\n let current: NodePath | null = tagPath.parentPath;\n while (current && current !== path) {\n if (\n current?.isSequenceExpression() &&\n last(current.node.expressions) === prev.node\n ) {\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isCallExpression({ callee: prev.node })) {\n const args = current.get('arguments');\n const cookedArgs = args\n .map((arg) => {\n const buildError = arg.buildCodeFrameError.bind(arg);\n if (!arg.isExpression()) {\n throw buildError(`Unexpected type of an argument ${arg.type}`);\n }\n const source = getSource(arg);\n const extracted = extractExpression(arg, options.evaluate, imports);\n return {\n ...extracted,\n source,\n buildCodeFrameError: buildError,\n } as ExpressionValue;\n })\n .filter(isNotNull);\n\n params.push(['call', ...cookedArgs]);\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isMemberExpression({ object: prev.node })) {\n const property = current.get('property');\n if (property.isIdentifier() && !current.node.computed) {\n params.push(['member', property.node.name]);\n } else if (property.isStringLiteral()) {\n params.push(['member', property.node.value]);\n } else {\n throw property.buildCodeFrameError(`Unexpected type of a property`);\n }\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isTaggedTemplateExpression({ tag: prev.node })) {\n const [quasis, expressionValues] = collectTemplateDependencies(\n current,\n options.evaluate\n );\n params.push(['template', zip(quasis, expressionValues)]);\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n break;\n }\n\n const replacer = (replacement: Expression, isPure: boolean) => {\n mutate(prev, (p) => {\n p.replaceWith(replacement);\n if (isPure) {\n p.addComment('leading', '#__PURE__');\n }\n });\n };\n\n const astService = {\n ...t,\n addDefaultImport: (importedSource: string, nameHint?: string) =>\n addDefault(path, importedSource, { nameHint }),\n addNamedImport: (\n name: string,\n importedSource: string,\n nameHint: string = name\n ) => addNamed(path, name, importedSource, { nameHint }),\n };\n\n return (...args: BuilderArgs) =>\n new Processor(\n params,\n tagSource,\n astService,\n tagPath.node.loc ?? null,\n replacer,\n ...args\n );\n}\n\nfunction getDisplayName(\n path: NodePath<Identifier>,\n idx: number,\n filename?: string | null\n): string {\n let displayName: string | undefined;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isObjectProperty()) {\n if ('name' in parent.node.key) {\n displayName = parent.node.key.name;\n } else if ('value' in parent.node.key) {\n displayName = parent.node.key.value.toString();\n } else {\n const keyPath = parent.get('key');\n displayName = getSource(keyPath);\n }\n } else if (parent.isJSXOpeningElement()) {\n const name = parent.get('name');\n if (name.isJSXIdentifier()) {\n displayName = name.node.name;\n }\n } else if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n if (id.isIdentifier()) {\n displayName = id.node.name;\n }\n }\n }\n\n if (!displayName) {\n // Try to derive the path from the filename\n displayName = basename(filename ?? 'unknown');\n\n if (filename && /^index\\.[a-z\\d]+$/.test(displayName)) {\n // If the file name is 'index', better to get name from parent folder\n displayName = basename(dirname(filename));\n }\n\n // Remove the file extension\n displayName = displayName.replace(/\\.[a-z\\d]+$/, '');\n\n if (displayName) {\n displayName += idx;\n } else {\n throw new Error(\n \"Couldn't determine a name for the component. Ensure that it's either:\\n\" +\n '- Assigned to a variable\\n' +\n '- Is an object property\\n' +\n '- Is a prop in a JSX element\\n'\n );\n }\n }\n\n return displayName;\n}\n\nfunction isTagReferenced(path: NodePath): boolean {\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n let isReferenced = true;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n // FIXME: replace with id.isReferencedIdentifier()\n if (id.isIdentifier()) {\n const { referencePaths } = path.scope.getBinding(id.node.name) || {\n referencePaths: [],\n };\n\n isReferenced = referencePaths.length !== 0;\n }\n }\n }\n\n return isReferenced;\n}\n\nconst counters = new WeakMap<IFileContext, number>();\nconst getNextIndex = (state: IFileContext) => {\n const counter = counters.get(state) ?? 0;\n counters.set(state, counter + 1);\n return counter;\n};\n\nexport function getTagProcessor(\n path: NodePath<Identifier>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >\n): BaseProcessor | null {\n const cache = getTraversalCache<BaseProcessor | null, Identifier>(\n path,\n 'getTagProcessor'\n );\n\n if (!cache.has(path.node)) {\n const root = path.scope.getProgramParent().path as NodePath<Program>;\n const { imports } = collectExportsAndImports(root);\n try {\n const builder = getBuilderForIdentifier(\n path,\n imports.filter(explicitImport),\n fileContext.filename,\n options\n );\n if (builder) {\n // Increment the index of the style we're processing\n // This is used for slug generation to prevent collision\n // Also used for display name if it couldn't be determined\n const idx = getNextIndex(fileContext);\n\n const displayName = getDisplayName(path, idx, fileContext.filename);\n\n const processor = builder(\n displayName,\n isTagReferenced(path),\n idx,\n options,\n fileContext\n );\n\n cache.set(path.node, processor);\n } else {\n cache.set(path.node, null);\n }\n } catch (e) {\n if (e === BaseProcessor.SKIP) {\n cache.set(path.node, null);\n return null;\n }\n\n if (e instanceof Error) {\n throw buildCodeFrameError(path, e.message);\n }\n\n throw e;\n }\n }\n\n return cache.get(path.node) ?? null;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,oBAAA,GAAAH,OAAA;AAUA,IAAAI,eAAA,GAAAJ,OAAA;AAOA,IAAAK,OAAA,GAAAL,OAAA;AAIA,IAAAM,yBAAA,GAAAN,OAAA;AAIA,IAAAO,4BAAA,GAAAP,OAAA;AAIA,IAAAQ,UAAA,GAAAR,OAAA;AACA,IAAAS,UAAA,GAAAT,OAAA;AACA,IAAAU,aAAA,GAAAV,OAAA;AACA,IAAAW,eAAA,GAAAX,OAAA;AAmBA,MAAMY,IAAI,GAAOC,GAAQ,IAAoBA,GAAG,CAACA,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC;AAEhE,SAASC,GAAGA,CAASC,IAAU,EAAEC,IAAU,EAAE;EAC3C,MAAMC,MAAmB,GAAG,EAAE;EAC9B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACF,MAAM,EAAEK,CAAC,EAAE,EAAE;IACpCD,MAAM,CAACE,IAAI,CAACJ,IAAI,CAACG,CAAC,CAAC,CAAC;IACpB,IAAIF,IAAI,CAACE,CAAC,CAAC,EAAED,MAAM,CAACE,IAAI,CAACH,IAAI,CAACE,CAAC,CAAC,CAAC;EACnC;EAEA,OAAOD,MAAM;AACf;AAEA,SAASG,mBAAmBA,CAAC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1B,OAAO,IAAI;MACb;MAEA,IAAIwG,CAAC,YAAY3J,KAAK,EAAE;QACtB,MAAMH,mBAAmB,CAACC,IAAI,EAAE6J,CAAC,CAAC5J,OAAO,CAAC;MAC5C;MAEA,MAAM4J,CAAC;IACT;EACF;EAEA,QAAAR,UAAA,GAAOC,KAAK,CAAC5I,GAAG,CAACV,IAAI,CAACqD,IAAI,CAAC,cAAAgG,UAAA,cAAAA,UAAA,GAAI,IAAI;AACrC"}
|
|
1
|
+
{"version":3,"file":"getTagProcessor.js","names":["_fs","require","_path","_core","_helperModuleImports","_processorUtils","_shared","_collectExportsAndImports","_collectTemplateDependencies","_getSource","_isNotNull","_scopeHelpers","_traversalCache","last","arr","length","zip","arr1","arr2","result","i","push","buildCodeFrameError","path","message","Error","definedTagsCache","Map","getDefinedTagsFromPackage","pkgName","filename","_packageJSON$wywInJ","has","get","packageJSONPath","findPackageJSON","undefined","packageDir","dirname","packageJSON","JSON","parse","readFileSync","definedTags","tags","normalizedTags","Object","entries","reduce","acc","key","value","startsWith","join","resolve","paths","set","isValidProcessorClass","module","BaseProcessor","constructor","getProcessorFromPackage","packageName","tagName","processorPath","Processor","default","getProcessorFromFile","getProcessorForImport","imported","source","options","_options$tagResolver","tagResolver","customFile","processor","getBuilderForIdentifier","definedProcessor","imports","_tagPath$parentPath","tagSource","tagPath","parentPath","isMemberExpression","property","node","params","prev","current","_current","_current2","_current3","_current4","isSequenceExpression","expressions","isCallExpression","callee","args","cookedArgs","map","arg","buildError","bind","isExpression","type","getSource","extracted","extractExpression","evaluate","filter","isNotNull","object","isIdentifier","computed","name","isStringLiteral","isTaggedTemplateExpression","tag","quasis","expressionValues","collectTemplateDependencies","replacer","replacement","isPure","mutate","p","replaceWith","addComment","importHelpers","addDefaultImport","importedSource","nameHint","addDefault","addNamedImport","addNamed","astService","Proxy","t","target","prop","receiver","Reflect","_tagPath$node$loc","loc","getDisplayName","idx","displayName","parent","findParent","isObjectProperty","isJSXOpeningElement","isVariableDeclarator","toString","keyPath","isJSXIdentifier","id","basename","test","replace","isTagReferenced","isReferenced","referencePaths","scope","getBinding","counters","WeakMap","getNextIndex","state","_counters$get","counter","getDefinedProcessors","cache","getTraversalCache","defined","forEach","local","createProcessorInstance","fileContext","_cache$get","builder","e","SKIP","applyProcessors","callback","collectExportsAndImports","explicitImport","definedProcessors","usages","idName","_path$scope$getBindin","includes","split","objBinding","identifier","sort","a","b","_a$identifier$node$st","_b$identifier$node$st","start","usage","instance"],"sources":["../../src/utils/getTagProcessor.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { basename, dirname, join } from 'path';\n\nimport { types as t } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport type { NodePath } from '@babel/traverse';\nimport type {\n Expression,\n Identifier,\n MemberExpression,\n Program,\n SourceLocation,\n} from '@babel/types';\n\nimport { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Param,\n Params,\n IFileContext,\n TagSource,\n} from '@wyw-in-js/processor-utils';\nimport { findPackageJSON } from '@wyw-in-js/shared';\nimport type { ExpressionValue, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { IImport } from './collectExportsAndImports';\nimport {\n collectExportsAndImports,\n explicitImport,\n} from './collectExportsAndImports';\nimport {\n collectTemplateDependencies,\n extractExpression,\n} from './collectTemplateDependencies';\nimport { getSource } from './getSource';\nimport { isNotNull } from './isNotNull';\nimport { mutate } from './scopeHelpers';\nimport { getTraversalCache } from './traversalCache';\n\ntype BuilderArgs = ConstructorParameters<typeof BaseProcessor> extends [\n Params,\n TagSource,\n typeof t,\n SourceLocation | null,\n (replacement: Expression, isPure: boolean) => void,\n ...infer T,\n]\n ? T\n : never;\n\ntype Builder = (...args: BuilderArgs) => BaseProcessor;\n\ntype DefinedProcessor = [ProcessorClass, TagSource];\ntype DefinedProcessors = Map<string, DefinedProcessor>;\n\nexport type ProcessorClass = new (\n ...args: ConstructorParameters<typeof BaseProcessor>\n) => BaseProcessor;\n\nconst last = <T>(arr: T[]): T | undefined => arr[arr.length - 1];\n\nfunction zip<T1, T2>(arr1: T1[], arr2: T2[]) {\n const result: (T1 | T2)[] = [];\n for (let i = 0; i < arr1.length; i++) {\n result.push(arr1[i]);\n if (arr2[i]) result.push(arr2[i]);\n }\n\n return result;\n}\n\nfunction buildCodeFrameError(path: NodePath, message: string): Error {\n try {\n return path.buildCodeFrameError(message);\n } catch {\n return new Error(message);\n }\n}\n\nconst definedTagsCache = new Map<string, Record<string, string> | undefined>();\nconst getDefinedTagsFromPackage = (\n pkgName: string,\n filename: string | null | undefined\n): Record<string, string> | undefined => {\n if (definedTagsCache.has(pkgName)) {\n return definedTagsCache.get(pkgName);\n }\n\n const packageJSONPath = findPackageJSON(pkgName, filename);\n if (!packageJSONPath) {\n return undefined;\n }\n\n const packageDir = dirname(packageJSONPath);\n const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'));\n const definedTags: Record<string, string> | undefined =\n packageJSON['wyw-in-js']?.tags;\n\n const normalizedTags = definedTags\n ? Object.entries(definedTags).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: value.startsWith('.')\n ? join(packageDir, value)\n : require.resolve(value, { paths: [packageDir] }),\n }),\n {} as Record<string, string>\n )\n : undefined;\n\n definedTagsCache.set(pkgName, normalizedTags);\n\n return normalizedTags;\n};\n\nfunction isValidProcessorClass(module: unknown): module is ProcessorClass {\n return module instanceof BaseProcessor.constructor;\n}\n\nfunction getProcessorFromPackage(\n packageName: string,\n tagName: string,\n filename: string | null | undefined\n): ProcessorClass | null {\n const definedTags = getDefinedTagsFromPackage(packageName, filename);\n const processorPath = definedTags?.[tagName];\n if (!processorPath) {\n return null;\n }\n\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nfunction getProcessorFromFile(processorPath: string): ProcessorClass | null {\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nexport function getProcessorForImport(\n { imported, source }: IImport,\n filename: string | null | undefined,\n options: Pick<StrictOptions, 'tagResolver'>\n): [ProcessorClass | null, TagSource] {\n const tagResolver = options.tagResolver ?? (() => null);\n\n const customFile = tagResolver(source, imported);\n const processor = customFile\n ? getProcessorFromFile(customFile)\n : getProcessorFromPackage(source, imported, filename);\n return [processor, { imported, source }];\n}\n\nfunction getBuilderForIdentifier(\n definedProcessor: DefinedProcessor,\n path: NodePath<Identifier>,\n imports: IImport[],\n options: Pick<StrictOptions, 'evaluate'>\n): Builder | null {\n const [Processor, tagSource] = definedProcessor;\n let tagPath: NodePath<Identifier | MemberExpression> = path;\n if (tagPath.parentPath?.isMemberExpression({ property: tagPath.node })) {\n tagPath = tagPath.parentPath;\n }\n\n if (!Processor || !tagSource || !tagPath) {\n return null;\n }\n\n const params: Param[] = [['callee', tagPath.node]];\n let prev: NodePath = tagPath;\n let current: NodePath | null = tagPath.parentPath;\n while (current && current !== path) {\n if (\n current?.isSequenceExpression() &&\n last(current.node.expressions) === prev.node\n ) {\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isCallExpression({ callee: prev.node })) {\n const args = current.get('arguments');\n const cookedArgs = args\n .map((arg) => {\n const buildError = arg.buildCodeFrameError.bind(arg);\n if (!arg.isExpression()) {\n throw buildError(`Unexpected type of an argument ${arg.type}`);\n }\n const source = getSource(arg);\n const extracted = extractExpression(arg, options.evaluate, imports);\n return {\n ...extracted,\n source,\n buildCodeFrameError: buildError,\n } as ExpressionValue;\n })\n .filter(isNotNull);\n\n params.push(['call', ...cookedArgs]);\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isMemberExpression({ object: prev.node })) {\n const property = current.get('property');\n if (property.isIdentifier() && !current.node.computed) {\n params.push(['member', property.node.name]);\n } else if (property.isStringLiteral()) {\n params.push(['member', property.node.value]);\n } else {\n throw property.buildCodeFrameError(`Unexpected type of a property`);\n }\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isTaggedTemplateExpression({ tag: prev.node })) {\n const [quasis, expressionValues] = collectTemplateDependencies(\n current,\n options.evaluate\n );\n params.push(['template', zip(quasis, expressionValues)]);\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n break;\n }\n\n const replacer = (replacement: Expression, isPure: boolean) => {\n mutate(prev, (p) => {\n p.replaceWith(replacement);\n if (isPure) {\n p.addComment('leading', '#__PURE__');\n }\n });\n };\n\n const importHelpers = {\n addDefaultImport: (importedSource: string, nameHint?: string) =>\n addDefault(path, importedSource, { nameHint }),\n addNamedImport: (\n name: string,\n importedSource: string,\n nameHint: string = name\n ) => addNamed(path, name, importedSource, { nameHint }),\n };\n\n type AstService = typeof t & typeof importHelpers;\n\n const astService = new Proxy<AstService>(t as AstService, {\n get(target, prop, receiver) {\n if (prop in importHelpers) {\n return importHelpers[prop as keyof typeof importHelpers];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n });\n\n return (...args: BuilderArgs) =>\n new Processor(\n params,\n tagSource,\n astService,\n tagPath.node.loc ?? null,\n replacer,\n ...args\n );\n}\n\nfunction getDisplayName(\n path: NodePath<Identifier>,\n idx: number,\n filename?: string | null\n): string {\n let displayName: string | undefined;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isObjectProperty()) {\n if ('name' in parent.node.key) {\n displayName = parent.node.key.name;\n } else if ('value' in parent.node.key) {\n displayName = parent.node.key.value.toString();\n } else {\n const keyPath = parent.get('key');\n displayName = getSource(keyPath);\n }\n } else if (parent.isJSXOpeningElement()) {\n const name = parent.get('name');\n if (name.isJSXIdentifier()) {\n displayName = name.node.name;\n }\n } else if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n if (id.isIdentifier()) {\n displayName = id.node.name;\n }\n }\n }\n\n if (!displayName) {\n // Try to derive the path from the filename\n displayName = basename(filename ?? 'unknown');\n\n if (filename && /^index\\.[a-z\\d]+$/.test(displayName)) {\n // If the file name is 'index', better to get name from parent folder\n displayName = basename(dirname(filename));\n }\n\n // Remove the file extension\n displayName = displayName.replace(/\\.[a-z\\d]+$/, '');\n\n if (displayName) {\n displayName += idx;\n } else {\n throw new Error(\n \"Couldn't determine a name for the component. Ensure that it's either:\\n\" +\n '- Assigned to a variable\\n' +\n '- Is an object property\\n' +\n '- Is a prop in a JSX element\\n'\n );\n }\n }\n\n return displayName;\n}\n\nfunction isTagReferenced(path: NodePath): boolean {\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n let isReferenced = true;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n // FIXME: replace with id.isReferencedIdentifier()\n if (id.isIdentifier()) {\n const { referencePaths } = path.scope.getBinding(id.node.name) || {\n referencePaths: [],\n };\n\n isReferenced = referencePaths.length !== 0;\n }\n }\n }\n\n return isReferenced;\n}\n\nconst counters = new WeakMap<IFileContext, number>();\nconst getNextIndex = (state: IFileContext) => {\n const counter = counters.get(state) ?? 0;\n counters.set(state, counter + 1);\n return counter;\n};\n\nexport function getDefinedProcessors(\n imports: IImport[],\n path: NodePath<Program>,\n filename: string | null | undefined,\n options: Pick<StrictOptions, 'tagResolver'>\n): DefinedProcessors {\n const cache = getTraversalCache<DefinedProcessors, NodePath<Program>>(\n path,\n 'getDefinedProcessors'\n );\n\n if (!cache.has(path)) {\n const defined: DefinedProcessors = new Map();\n\n imports.forEach((i) => {\n const [processor, tagSource] = getProcessorForImport(\n i,\n filename,\n options\n );\n const { local } = i;\n if (!processor) {\n return;\n }\n\n let name: string | null = null;\n if (local.isIdentifier()) {\n name = local.node.name;\n }\n\n if (name === null && local.isMemberExpression()) {\n const property = local.get('property');\n const object = local.get('object');\n if (property.isIdentifier() && object.isIdentifier()) {\n name = `${object.node.name}.${property.node.name}`;\n }\n }\n\n if (name === null) {\n return;\n }\n\n defined.set(name, [processor, tagSource]);\n });\n\n cache.set(path, defined);\n }\n\n return cache.get(path)!;\n}\n\nfunction createProcessorInstance(\n definedProcessor: [ProcessorClass, TagSource],\n imports: IImport[],\n path: NodePath<Identifier>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >\n): BaseProcessor | null {\n const cache = getTraversalCache<BaseProcessor | null, Identifier>(\n path,\n 'createProcessorInstance'\n );\n\n if (!cache.has(path.node)) {\n try {\n const builder = getBuilderForIdentifier(\n definedProcessor,\n path,\n imports,\n options\n );\n if (builder) {\n // Increment the index of the style we're processing\n // This is used for slug generation to prevent collision\n // Also used for display name if it couldn't be determined\n const idx = getNextIndex(fileContext);\n\n const displayName = getDisplayName(path, idx, fileContext.filename);\n\n const processor = builder(\n displayName,\n isTagReferenced(path),\n idx,\n options,\n fileContext\n );\n\n cache.set(path.node, processor);\n } else {\n cache.set(path.node, null);\n }\n } catch (e) {\n if (e === BaseProcessor.SKIP) {\n cache.set(path.node, null);\n return null;\n }\n\n if (e instanceof Error) {\n throw buildCodeFrameError(path, e.message);\n }\n\n throw e;\n }\n }\n\n return cache.get(path.node) ?? null;\n}\n\nexport function applyProcessors(\n path: NodePath<Program>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >,\n callback: (processor: BaseProcessor) => void\n) {\n const imports = collectExportsAndImports(path).imports.filter(explicitImport);\n\n const definedProcessors = getDefinedProcessors(\n imports,\n path,\n fileContext.filename,\n options\n );\n\n const usages: {\n identifier: NodePath<Identifier>;\n processor: DefinedProcessor;\n }[] = [];\n\n definedProcessors.forEach((processor, idName) => {\n if (idName.includes('.')) {\n // It's a member expression\n const [object, property] = idName.split('.');\n const objBinding = path.scope.getBinding(object);\n if (!objBinding) {\n return;\n }\n\n objBinding.referencePaths.forEach((p) => {\n const parent = p.parentPath;\n if (!parent?.isMemberExpression()) {\n return;\n }\n\n const identifier = parent.get('property');\n if (identifier.isIdentifier({ name: property })) {\n usages.push({\n identifier,\n processor,\n });\n }\n });\n\n return;\n }\n\n path.scope.getBinding(idName)?.referencePaths.forEach((identifier) => {\n if (identifier.isIdentifier()) {\n usages.push({\n identifier,\n processor,\n });\n }\n });\n });\n\n // The same order, the same slugs\n usages.sort(\n (a, b) => (a.identifier.node.start ?? 0) - (b.identifier.node.start ?? 0)\n );\n\n usages.forEach((usage) => {\n const definedProcessor = usage.processor;\n\n if (!definedProcessor) {\n return;\n }\n\n const instance = createProcessorInstance(\n definedProcessor,\n imports,\n usage.identifier,\n fileContext,\n options\n );\n\n if (instance === null) {\n return;\n }\n\n callback(instance);\n });\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,GAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,oBAAA,GAAAH,OAAA;AAUA,IAAAI,eAAA,GAAAJ,OAAA;AAOA,IAAAK,OAAA,GAAAL,OAAA;AAIA,IAAAM,yBAAA,GAAAN,OAAA;AAIA,IAAAO,4BAAA,GAAAP,OAAA;AAIA,IAAAQ,UAAA,GAAAR,OAAA;AACA,IAAAS,UAAA,GAAAT,OAAA;AACA,IAAAU,aAAA,GAAAV,OAAA;AACA,IAAAW,eAAA,GAAAX,OAAA;AAsBA,MAAMY,IAAI,GAAOC,GAAQ,IAAoBA,GAAG,CAACA,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC;AAEhE,SAASC,GAAGA,CAASC,IAAU,EAAEC,IAAU,EAAE;EAC3C,MAAMC,MAAmB,GAAG,EAAE;EAC9B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACF,MAAM,EAAEK,CAAC,EAAE,EAA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C,IAAI,CAACE,gBAAgB,EAAE;MACrB;IACF;IAEA,MAAM4H,QAAQ,GAAGzB,uBAAuB,CACtCnG,gBAAgB,EAChBC,OAAO,EACP0H,KAAK,CAACP,UAAU,EAChBhB,WAAW,EACX1G,OACF,CAAC;IAED,IAAIkI,QAAQ,KAAK,IAAI,EAAE;MACrB;IACF;IAEAlB,QAAQ,CAACkB,QAAQ,CAAC;EACpB,CAAC,CAAC;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyw-in-js/transform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@babel/core": "^7.23.5",
|
|
6
6
|
"@babel/generator": "^7.23.5",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"source-map": "^0.7.4",
|
|
16
16
|
"stylis": "^4.3.0",
|
|
17
17
|
"ts-invariant": "^0.10.3",
|
|
18
|
-
"@wyw-in-js/processor-utils": "0.
|
|
19
|
-
"@wyw-in-js/shared": "0.
|
|
18
|
+
"@wyw-in-js/processor-utils": "0.4.1",
|
|
19
|
+
"@wyw-in-js/shared": "0.4.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@babel/plugin-syntax-typescript": "^7.23.3",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"glob": "^10.3.10",
|
|
38
38
|
"strip-ansi": "^5.2.0",
|
|
39
39
|
"typescript": "^5.2.2",
|
|
40
|
-
"@wyw-in-js/babel-config": "0.
|
|
41
|
-
"@wyw-in-js/eslint-config": "0.
|
|
42
|
-
"@wyw-in-js/jest-preset": "0.
|
|
43
|
-
"@wyw-in-js/ts-config": "0.
|
|
40
|
+
"@wyw-in-js/babel-config": "0.4.1",
|
|
41
|
+
"@wyw-in-js/eslint-config": "0.4.1",
|
|
42
|
+
"@wyw-in-js/jest-preset": "0.4.1",
|
|
43
|
+
"@wyw-in-js/ts-config": "0.4.1"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=16.0.0"
|
package/types/index.d.ts
CHANGED
|
@@ -26,10 +26,9 @@ export { EventEmitter } from './utils/EventEmitter';
|
|
|
26
26
|
export type { EntrypointEvent, OnEvent, OnActionStartArgs, OnActionFinishArgs, } from './utils/EventEmitter';
|
|
27
27
|
export { isNode } from './utils/isNode';
|
|
28
28
|
export { getFileIdx } from './utils/getFileIdx';
|
|
29
|
-
export {
|
|
29
|
+
export { applyProcessors } from './utils/getTagProcessor';
|
|
30
30
|
export { getVisitorKeys } from './utils/getVisitorKeys';
|
|
31
31
|
export type { VisitorKeys } from './utils/getVisitorKeys';
|
|
32
32
|
export { peek } from './utils/peek';
|
|
33
|
-
export { processTemplateExpression } from './utils/processTemplateExpression';
|
|
34
33
|
export { TransformCacheCollection } from './cache';
|
|
35
34
|
export { findIdentifiers } from './utils/findIdentifiers';
|
package/types/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.findIdentifiers = exports.TransformCacheCollection = exports.
|
|
20
|
+
exports.findIdentifiers = exports.TransformCacheCollection = exports.peek = exports.getVisitorKeys = exports.applyProcessors = exports.getFileIdx = exports.isNode = exports.EventEmitter = exports.withDefaultServices = exports.loadWywOptions = exports.syncResolveImports = exports.asyncResolveImports = exports.transformUrl = exports.Entrypoint = exports.prepareCode = exports.baseHandlers = exports.parseFile = exports.EvaluatedEntrypoint = exports.UnprocessedEntrypointError = exports.isUnprocessedEntrypointError = exports.transform = exports.shaker = exports.DefaultModuleImplementation = exports.Module = exports.withTransformMetadata = exports.getTransformMetadata = exports.preeval = exports.babelTransformPlugin = exports.createFileReporter = exports.slugify = void 0;
|
|
21
21
|
var shared_1 = require("@wyw-in-js/shared");
|
|
22
22
|
Object.defineProperty(exports, "slugify", { enumerable: true, get: function () { return shared_1.slugify; } });
|
|
23
23
|
var fileReporter_1 = require("./debug/fileReporter");
|
|
@@ -66,13 +66,11 @@ Object.defineProperty(exports, "isNode", { enumerable: true, get: function () {
|
|
|
66
66
|
var getFileIdx_1 = require("./utils/getFileIdx");
|
|
67
67
|
Object.defineProperty(exports, "getFileIdx", { enumerable: true, get: function () { return getFileIdx_1.getFileIdx; } });
|
|
68
68
|
var getTagProcessor_1 = require("./utils/getTagProcessor");
|
|
69
|
-
Object.defineProperty(exports, "
|
|
69
|
+
Object.defineProperty(exports, "applyProcessors", { enumerable: true, get: function () { return getTagProcessor_1.applyProcessors; } });
|
|
70
70
|
var getVisitorKeys_1 = require("./utils/getVisitorKeys");
|
|
71
71
|
Object.defineProperty(exports, "getVisitorKeys", { enumerable: true, get: function () { return getVisitorKeys_1.getVisitorKeys; } });
|
|
72
72
|
var peek_1 = require("./utils/peek");
|
|
73
73
|
Object.defineProperty(exports, "peek", { enumerable: true, get: function () { return peek_1.peek; } });
|
|
74
|
-
var processTemplateExpression_1 = require("./utils/processTemplateExpression");
|
|
75
|
-
Object.defineProperty(exports, "processTemplateExpression", { enumerable: true, get: function () { return processTemplateExpression_1.processTemplateExpression; } });
|
|
76
74
|
var cache_1 = require("./cache");
|
|
77
75
|
Object.defineProperty(exports, "TransformCacheCollection", { enumerable: true, get: function () { return cache_1.TransformCacheCollection; } });
|
|
78
76
|
var findIdentifiers_1 = require("./utils/findIdentifiers");
|
|
@@ -5,12 +5,16 @@
|
|
|
5
5
|
import type { BabelFile, PluginObj } from '@babel/core';
|
|
6
6
|
import type { ValueCache } from '@wyw-in-js/processor-utils';
|
|
7
7
|
import type { StrictOptions } from '@wyw-in-js/shared';
|
|
8
|
+
import { EventEmitter } from '../utils/EventEmitter';
|
|
8
9
|
import type { Core } from '../babel';
|
|
9
10
|
import type { IPluginState } from '../types';
|
|
10
11
|
export declare const filename: string;
|
|
11
|
-
export declare function collector(file: BabelFile, options: Pick<StrictOptions, 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'
|
|
12
|
+
export declare function collector(file: BabelFile, options: Pick<StrictOptions, 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'> & {
|
|
13
|
+
eventEmitter?: EventEmitter;
|
|
14
|
+
}, values: ValueCache): {
|
|
12
15
|
artifacts: import("@wyw-in-js/shared").Artifact[];
|
|
13
16
|
}[];
|
|
14
17
|
export default function collectorPlugin(babel: Core, options: StrictOptions & {
|
|
18
|
+
eventEmitter?: EventEmitter;
|
|
15
19
|
values?: ValueCache;
|
|
16
20
|
}): PluginObj<IPluginState>;
|
|
@@ -6,21 +6,16 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.collector = exports.filename = void 0;
|
|
8
8
|
const shared_1 = require("@wyw-in-js/shared");
|
|
9
|
-
const
|
|
9
|
+
const EventEmitter_1 = require("../utils/EventEmitter");
|
|
10
|
+
const getTagProcessor_1 = require("../utils/getTagProcessor");
|
|
10
11
|
const scopeHelpers_1 = require("../utils/scopeHelpers");
|
|
11
12
|
const traversalCache_1 = require("../utils/traversalCache");
|
|
12
13
|
exports.filename = __filename;
|
|
13
14
|
function collector(file, options, values) {
|
|
15
|
+
const eventEmitter = options.eventEmitter ?? EventEmitter_1.EventEmitter.dummy;
|
|
14
16
|
const processors = [];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Identifier: (p) => {
|
|
18
|
-
identifiers.push(p);
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
// TODO: process transformed literals
|
|
22
|
-
identifiers.forEach((p) => {
|
|
23
|
-
(0, processTemplateExpression_1.processTemplateExpression)(p, file.opts, options, (processor) => {
|
|
17
|
+
eventEmitter.perf('transform:collector:processTemplate', () => {
|
|
18
|
+
(0, getTagProcessor_1.applyProcessors)(file.path, file.opts, options, (processor) => {
|
|
24
19
|
processor.build(values);
|
|
25
20
|
processor.doRuntimeReplacement();
|
|
26
21
|
processors.push(processor);
|
|
@@ -7,10 +7,10 @@ import type { StrictOptions } from '@wyw-in-js/shared';
|
|
|
7
7
|
import type { Core } from '../babel';
|
|
8
8
|
import type { IPluginState } from '../types';
|
|
9
9
|
import { EventEmitter } from '../utils/EventEmitter';
|
|
10
|
-
export type PreevalOptions = Pick<StrictOptions, 'classNameSlug' | 'displayName' | 'evaluate' | 'features'> & {
|
|
11
|
-
eventEmitter
|
|
10
|
+
export type PreevalOptions = Pick<StrictOptions, 'classNameSlug' | 'displayName' | 'evaluate' | 'features' | 'tagResolver'> & {
|
|
11
|
+
eventEmitter?: EventEmitter;
|
|
12
12
|
};
|
|
13
|
-
export declare function preeval(babel: Core,
|
|
13
|
+
export declare function preeval(babel: Core, options: PreevalOptions): PluginObj<IPluginState & {
|
|
14
14
|
onFinish: () => void;
|
|
15
15
|
}>;
|
|
16
16
|
export default preeval;
|
package/types/plugins/preeval.js
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.preeval = void 0;
|
|
4
4
|
const shared_1 = require("@wyw-in-js/shared");
|
|
5
|
+
const getTagProcessor_1 = require("../utils/getTagProcessor");
|
|
5
6
|
const EventEmitter_1 = require("../utils/EventEmitter");
|
|
6
7
|
const addIdentifierToWywPreval_1 = require("../utils/addIdentifierToWywPreval");
|
|
7
8
|
const getFileIdx_1 = require("../utils/getFileIdx");
|
|
8
|
-
const processTemplateExpression_1 = require("../utils/processTemplateExpression");
|
|
9
9
|
const removeDangerousCode_1 = require("../utils/removeDangerousCode");
|
|
10
10
|
const traversalCache_1 = require("../utils/traversalCache");
|
|
11
|
-
function preeval(babel,
|
|
11
|
+
function preeval(babel, options) {
|
|
12
12
|
const { types: t } = babel;
|
|
13
|
+
const eventEmitter = options.eventEmitter ?? EventEmitter_1.EventEmitter.dummy;
|
|
13
14
|
return {
|
|
14
15
|
name: '@wyw-in-js/transform/preeval',
|
|
15
16
|
pre(file) {
|
|
@@ -19,18 +20,14 @@ function preeval(babel, { eventEmitter = EventEmitter_1.EventEmitter.dummy, ...o
|
|
|
19
20
|
const rootScope = file.scope;
|
|
20
21
|
this.processors = [];
|
|
21
22
|
eventEmitter.perf('transform:preeval:processTemplate', () => {
|
|
22
|
-
file.path.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
processor.doEvaltimeReplacement();
|
|
31
|
-
this.processors.push(processor);
|
|
32
|
-
});
|
|
33
|
-
},
|
|
23
|
+
(0, getTagProcessor_1.applyProcessors)(file.path, file.opts, options, (processor) => {
|
|
24
|
+
processor.dependencies.forEach((dependency) => {
|
|
25
|
+
if (dependency.ex.type === 'Identifier') {
|
|
26
|
+
(0, addIdentifierToWywPreval_1.addIdentifierToWywPreval)(rootScope, dependency.ex.name);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
processor.doEvaltimeReplacement();
|
|
30
|
+
this.processors.push(processor);
|
|
34
31
|
});
|
|
35
32
|
});
|
|
36
33
|
if ((0, shared_1.isFeatureEnabled)(options.features, 'dangerousCodeRemover', filename)) {
|
|
@@ -43,7 +43,10 @@ class Entrypoint extends BaseEntrypoint_1.BaseEntrypoint {
|
|
|
43
43
|
if (this.loadedAndParsed.code !== undefined) {
|
|
44
44
|
services.cache.invalidateIfChanged(name, this.loadedAndParsed.code);
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
const code = this.loadedAndParsed.evaluator === 'ignored'
|
|
47
|
+
? '[IGNORED]'
|
|
48
|
+
: this.originalCode || EMPTY_FILE;
|
|
49
|
+
this.log.extend('source')('created %s (%o)\n%s', name, only, code);
|
|
47
50
|
}
|
|
48
51
|
get ignored() {
|
|
49
52
|
return this.loadedAndParsed.evaluator === 'ignored';
|
|
@@ -8,4 +8,7 @@ export declare function transformUrl(url: string, outputFilename: string, source
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const stylisGlobalPlugin: Middleware;
|
|
10
10
|
export declare function createStylisUrlReplacePlugin(filename: string, outputFilename: string | undefined): Middleware;
|
|
11
|
-
export declare function
|
|
11
|
+
export declare function createKeyframeSuffixerPlugin(): Middleware;
|
|
12
|
+
export declare function createStylisPreprocessor(options: Options & {
|
|
13
|
+
prefixer?: boolean;
|
|
14
|
+
}): (selector: string, text: string) => string;
|