@wyw-in-js/transform 0.1.1 → 0.2.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.
Files changed (142) hide show
  1. package/esm/index.js +4 -1
  2. package/esm/index.js.map +1 -1
  3. package/esm/options/loadBabelOptions.js +1 -1
  4. package/esm/options/loadBabelOptions.js.map +1 -1
  5. package/esm/plugins/babel-transform.js +2 -2
  6. package/esm/plugins/babel-transform.js.map +1 -1
  7. package/esm/plugins/collector.js +4 -4
  8. package/esm/plugins/collector.js.map +1 -1
  9. package/esm/plugins/preeval.js +11 -11
  10. package/esm/plugins/preeval.js.map +1 -1
  11. package/esm/plugins/shaker.js +5 -5
  12. package/esm/plugins/shaker.js.map +1 -1
  13. package/esm/shaker.js +2 -2
  14. package/esm/shaker.js.map +1 -1
  15. package/esm/transform/Entrypoint.helpers.js +1 -2
  16. package/esm/transform/Entrypoint.helpers.js.map +1 -1
  17. package/esm/transform/Entrypoint.js +4 -4
  18. package/esm/transform/Entrypoint.js.map +1 -1
  19. package/esm/transform/generators/collect.js +3 -2
  20. package/esm/transform/generators/collect.js.map +1 -1
  21. package/esm/transform/generators/evalFile.js +6 -6
  22. package/esm/transform/generators/evalFile.js.map +1 -1
  23. package/esm/transform/generators/extract.js +18 -14
  24. package/esm/transform/generators/extract.js.map +1 -1
  25. package/esm/transform/generators/transform.js +2 -2
  26. package/esm/transform/generators/transform.js.map +1 -1
  27. package/esm/transform/generators/workflow.js +3 -3
  28. package/esm/transform/generators/workflow.js.map +1 -1
  29. package/esm/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +5 -5
  30. package/esm/transform/helpers/loadWywOptions.js.map +1 -0
  31. package/esm/transform.js +11 -10
  32. package/esm/transform.js.map +1 -1
  33. package/esm/types.js.map +1 -1
  34. package/esm/utils/ShakerMetadata.js +1 -1
  35. package/esm/utils/ShakerMetadata.js.map +1 -1
  36. package/esm/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +10 -10
  37. package/esm/utils/addIdentifierToWywPreval.js.map +1 -0
  38. package/esm/utils/collectExportsAndImports.js +141 -53
  39. package/esm/utils/collectExportsAndImports.js.map +1 -1
  40. package/esm/utils/collectTemplateDependencies.js +2 -2
  41. package/esm/utils/collectTemplateDependencies.js.map +1 -1
  42. package/esm/utils/getTagProcessor.js +1 -1
  43. package/esm/utils/getTagProcessor.js.map +1 -1
  44. package/esm/utils/hasWywPreval.js +7 -0
  45. package/esm/utils/hasWywPreval.js.map +1 -0
  46. package/lib/index.js +28 -4
  47. package/lib/index.js.map +1 -1
  48. package/lib/options/loadBabelOptions.js +1 -1
  49. package/lib/options/loadBabelOptions.js.map +1 -1
  50. package/lib/plugins/babel-transform.js +2 -2
  51. package/lib/plugins/babel-transform.js.map +1 -1
  52. package/lib/plugins/collector.js +4 -4
  53. package/lib/plugins/collector.js.map +1 -1
  54. package/lib/plugins/preeval.js +11 -11
  55. package/lib/plugins/preeval.js.map +1 -1
  56. package/lib/plugins/shaker.js +5 -5
  57. package/lib/plugins/shaker.js.map +1 -1
  58. package/lib/shaker.js +2 -2
  59. package/lib/shaker.js.map +1 -1
  60. package/lib/transform/Entrypoint.helpers.js +1 -2
  61. package/lib/transform/Entrypoint.helpers.js.map +1 -1
  62. package/lib/transform/Entrypoint.js +4 -4
  63. package/lib/transform/Entrypoint.js.map +1 -1
  64. package/lib/transform/generators/collect.js +1 -1
  65. package/lib/transform/generators/collect.js.map +1 -1
  66. package/lib/transform/generators/evalFile.js +6 -6
  67. package/lib/transform/generators/evalFile.js.map +1 -1
  68. package/lib/transform/generators/extract.js +18 -14
  69. package/lib/transform/generators/extract.js.map +1 -1
  70. package/lib/transform/generators/transform.js +2 -2
  71. package/lib/transform/generators/transform.js.map +1 -1
  72. package/lib/transform/generators/workflow.js +3 -3
  73. package/lib/transform/generators/workflow.js.map +1 -1
  74. package/lib/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +6 -6
  75. package/lib/transform/helpers/loadWywOptions.js.map +1 -0
  76. package/lib/transform/helpers/withDefaultServices.js +2 -2
  77. package/lib/transform/helpers/withDefaultServices.js.map +1 -1
  78. package/lib/transform.js +11 -10
  79. package/lib/transform.js.map +1 -1
  80. package/lib/types.js.map +1 -1
  81. package/lib/utils/ShakerMetadata.js +1 -1
  82. package/lib/utils/ShakerMetadata.js.map +1 -1
  83. package/lib/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +12 -12
  84. package/lib/utils/addIdentifierToWywPreval.js.map +1 -0
  85. package/lib/utils/collectExportsAndImports.js +141 -53
  86. package/lib/utils/collectExportsAndImports.js.map +1 -1
  87. package/lib/utils/collectTemplateDependencies.js +2 -2
  88. package/lib/utils/collectTemplateDependencies.js.map +1 -1
  89. package/lib/utils/getTagProcessor.js +2 -2
  90. package/lib/utils/getTagProcessor.js.map +1 -1
  91. package/lib/utils/hasWywPreval.js +13 -0
  92. package/lib/utils/hasWywPreval.js.map +1 -0
  93. package/lib/vm/createVmContext.js +2 -2
  94. package/lib/vm/createVmContext.js.map +1 -1
  95. package/package.json +24 -21
  96. package/types/index.d.ts +5 -2
  97. package/types/index.js +9 -3
  98. package/types/options/loadBabelOptions.js +1 -1
  99. package/types/plugins/babel-transform.js +2 -2
  100. package/types/plugins/collector.js +4 -4
  101. package/types/plugins/preeval.js +11 -11
  102. package/types/plugins/shaker.js +5 -5
  103. package/types/shaker.js +2 -2
  104. package/types/transform/Entrypoint.d.ts +1 -1
  105. package/types/transform/Entrypoint.helpers.js +3 -3
  106. package/types/transform/Entrypoint.js +4 -4
  107. package/types/transform/generators/collect.js +1 -1
  108. package/types/transform/generators/evalFile.js +7 -7
  109. package/types/transform/generators/extract.js +21 -12
  110. package/types/transform/generators/transform.js +2 -4
  111. package/types/transform/generators/workflow.js +3 -3
  112. package/types/transform/helpers/{loadLinariaOptions.d.ts → loadWywOptions.d.ts} +1 -1
  113. package/types/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +19 -19
  114. package/types/transform.d.ts +7 -6
  115. package/types/transform.js +11 -10
  116. package/types/types.d.ts +1 -1
  117. package/types/utils/ShakerMetadata.d.ts +1 -1
  118. package/types/utils/ShakerMetadata.js +1 -1
  119. package/types/utils/addIdentifierToWywPreval.d.ts +4 -0
  120. package/types/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +12 -12
  121. package/types/utils/collectExportsAndImports.js +157 -58
  122. package/types/utils/collectTemplateDependencies.d.ts +1 -1
  123. package/types/utils/collectTemplateDependencies.js +2 -2
  124. package/types/utils/getTagProcessor.js +2 -2
  125. package/types/utils/hasWywPreval.d.ts +4 -0
  126. package/types/utils/{hasLinariaPreval.js → hasWywPreval.js} +3 -3
  127. package/esm/transform/helpers/loadLinariaOptions.js.map +0 -1
  128. package/esm/utils/addIdentifierToLinariaPreval.js.map +0 -1
  129. package/esm/utils/findPackageJSON.js +0 -26
  130. package/esm/utils/findPackageJSON.js.map +0 -1
  131. package/esm/utils/hasLinariaPreval.js +0 -7
  132. package/esm/utils/hasLinariaPreval.js.map +0 -1
  133. package/lib/transform/helpers/loadLinariaOptions.js.map +0 -1
  134. package/lib/utils/addIdentifierToLinariaPreval.js.map +0 -1
  135. package/lib/utils/findPackageJSON.js +0 -35
  136. package/lib/utils/findPackageJSON.js.map +0 -1
  137. package/lib/utils/hasLinariaPreval.js +0 -13
  138. package/lib/utils/hasLinariaPreval.js.map +0 -1
  139. package/types/utils/addIdentifierToLinariaPreval.d.ts +0 -4
  140. package/types/utils/findPackageJSON.d.ts +0 -1
  141. package/types/utils/findPackageJSON.js +0 -56
  142. package/types/utils/hasLinariaPreval.d.ts +0 -4
@@ -1 +1 @@
1
- {"version":3,"file":"getTagProcessor.js","names":["_fs","require","_path","_core","_helperModuleImports","_processorUtils","_collectExportsAndImports","_collectTemplateDependencies","_findPackageJSON","_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 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 { findPackageJSON } from './findPackageJSON';\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;AAUA,IAAAK,yBAAA,GAAAL,OAAA;AAIA,IAAAM,4BAAA,GAAAN,OAAA;AAIA,IAAAO,gBAAA,GAAAP,OAAA;AACA,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,CAACC,IAAc,EAAEC,OAAe,EAAS;EACnE,IAAI;IACF,OAAOD,IAAI,CAACD,mBAAmB,CAACE,OAAO,CAAC;EAC1C,CAAC,CAAC,MAAM;IACN,OAAO,IAAIC,KAAK,CAACD,OAAO,CAAC;E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ACT;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","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,CA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MAC5B;IACF,CAAC,CAAC,OAAOwG,CAAC,EAAE;MACV,IAAIA,CAAC,KAAKzH,6BAAa,CAAC0H,IAAI,EAAE;QAC5BR,KAAK,CAACrH,GAAG,CAACjC,IAAI,CAACqD,IAAI,EAAE,IAAI,CAAC;QAC1B,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"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = hasWywPreval;
7
+ function hasWywPreval(exports) {
8
+ if (!exports || typeof exports !== 'object') {
9
+ return false;
10
+ }
11
+ return '__wywPreval' in exports;
12
+ }
13
+ //# sourceMappingURL=hasWywPreval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasWywPreval.js","names":["hasWywPreval","exports"],"sources":["../../src/utils/hasWywPreval.ts"],"sourcesContent":["import type { Value } from '@wyw-in-js/processor-utils';\n\nexport default function hasWywPreval(exports: unknown): exports is {\n __wywPreval: Record<string, () => Value> | null | undefined;\n} {\n if (!exports || typeof exports !== 'object') {\n return false;\n }\n\n return '__wywPreval' in exports;\n}\n"],"mappings":";;;;;;AAEe,SAASA,YAAYA,CAACC,OAAgB,EAEnD;EACA,IAAI,CAACA,OAAO,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;IAC3C,OAAO,KAAK;EACd;EAEA,OAAO,aAAa,IAAIA,OAAO;AACjC"}
@@ -7,8 +7,8 @@ exports.createVmContext = createVmContext;
7
7
  var vm = _interopRequireWildcard(require("vm"));
8
8
  var _shared = require("@wyw-in-js/shared");
9
9
  var process = _interopRequireWildcard(require("./process"));
10
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
12
  const NOOP = () => {};
13
13
  function createWindow() {
14
14
  const {
@@ -1 +1 @@
1
- {"version":3,"file":"createVmContext.js","names":["vm","_interopRequireWildcard","require","_shared","process","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","NOOP","createWindow","Window","GlobalWindow","HappyWindow","win","Buffer","Uint8Array","createBaseContext","additionalContext","baseContext","document","window","self","top","parent","global","clearImmediate","clearInterval","clearTimeout","setImmediate","requestAnimationFrame","setInterval","setTimeout","createHappyDOMWindow","teardown","happyDOM","cancelAsync","createNothing","undefined","createVmContext","filename","features","overrideContext","i","isHappyDOMEnabled","isFeatureEnabled","__filename","context","createContext"],"sources":["../../src/vm/createVmContext.ts"],"sourcesContent":["import * as vm from 'vm';\n\nimport type { Window } from 'happy-dom';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\nimport { isFeatureEnabled } from '@wyw-in-js/shared';\n\nimport * as process from './process';\n\nconst NOOP = () => {};\n\nfunction createWindow(): Window {\n const { Window, GlobalWindow } = require('happy-dom');\n const HappyWindow = GlobalWindow || Window;\n const win = new HappyWindow();\n\n // TODO: browser doesn't expose Buffer, but a lot of dependencies use it\n win.Buffer = Buffer;\n win.Uint8Array = Uint8Array;\n\n return win;\n}\n\nfunction createBaseContext(\n win: Window | undefined,\n additionalContext: Partial<vm.Context>\n): Partial<vm.Context> {\n const baseContext: vm.Context = win ?? {};\n\n baseContext.document = win?.document;\n baseContext.window = win;\n baseContext.self = win;\n baseContext.top = win;\n baseContext.parent = win;\n baseContext.global = win;\n\n baseContext.process = process;\n\n baseContext.clearImmediate = NOOP;\n baseContext.clearInterval = NOOP;\n baseContext.clearTimeout = NOOP;\n baseContext.setImmediate = NOOP;\n baseContext.requestAnimationFrame = NOOP;\n baseContext.setInterval = NOOP;\n baseContext.setTimeout = NOOP;\n\n // eslint-disable-next-line guard-for-in,no-restricted-syntax\n for (const key in additionalContext) {\n baseContext[key] = additionalContext[key];\n }\n\n return baseContext;\n}\n\nfunction createHappyDOMWindow() {\n const win = createWindow();\n\n return {\n teardown: () => {\n win.happyDOM.cancelAsync();\n },\n window: win,\n };\n}\n\nfunction createNothing() {\n return {\n teardown: () => {},\n window: undefined,\n };\n}\n\nexport function createVmContext(\n filename: string,\n features: FeatureFlags<'happyDOM'>,\n additionalContext: Partial<vm.Context>,\n overrideContext: StrictOptions['overrideContext'] = (i) => i\n) {\n const isHappyDOMEnabled = isFeatureEnabled(features, 'happyDOM', filename);\n\n const { teardown, window } = isHappyDOMEnabled\n ? createHappyDOMWindow()\n : createNothing();\n const baseContext = createBaseContext(\n window,\n overrideContext(\n {\n __filename: filename,\n ...additionalContext,\n },\n filename\n )\n );\n\n const context = vm.createContext(baseContext);\n\n return {\n context,\n teardown,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,EAAA,GAAAC,uBAAA,CAAAC,OAAA;AAKA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,OAAA,GAAAH,uBAAA,CAAAC,OAAA;AAAqC,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAL,wBAAAS,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAA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Q;IACpB,GAAGtB;EACL,CAAC,EACDsB,QACF,CACF,CAAC;EAED,MAAMO,OAAO,GAAGjE,EAAE,CAACkE,aAAa,CAAC7B,WAAW,CAAC;EAE7C,OAAO;IACL4B,OAAO;IACPb;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"createVmContext.js","names":["vm","_interopRequireWildcard","require","_shared","process","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","NOOP","createWindow","Window","GlobalWindow","HappyWindow","win","Buffer","Uint8Array","createBaseContext","additionalContext","baseContext","document","window","self","top","parent","global","clearImmediate","clearInterval","clearTimeout","setImmediate","requestAnimationFrame","setInterval","setTimeout","key","createHappyDOMWindow","teardown","happyDOM","cancelAsync","createNothing","undefined","createVmContext","filename","features","overrideContext","isHappyDOMEnabled","isFeatureEnabled","__filename","context","createContext"],"sources":["../../src/vm/createVmContext.ts"],"sourcesContent":["import * as vm from 'vm';\n\nimport type { Window } from 'happy-dom';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\nimport { isFeatureEnabled } from '@wyw-in-js/shared';\n\nimport * as process from './process';\n\nconst NOOP = () => {};\n\nfunction createWindow(): Window {\n const { Window, GlobalWindow } = require('happy-dom');\n const HappyWindow = GlobalWindow || Window;\n const win = new HappyWindow();\n\n // TODO: browser doesn't expose Buffer, but a lot of dependencies use it\n win.Buffer = Buffer;\n win.Uint8Array = Uint8Array;\n\n return win;\n}\n\nfunction createBaseContext(\n win: Window | undefined,\n additionalContext: Partial<vm.Context>\n): Partial<vm.Context> {\n const baseContext: vm.Context = win ?? {};\n\n baseContext.document = win?.document;\n baseContext.window = win;\n baseContext.self = win;\n baseContext.top = win;\n baseContext.parent = win;\n baseContext.global = win;\n\n baseContext.process = process;\n\n baseContext.clearImmediate = NOOP;\n baseContext.clearInterval = NOOP;\n baseContext.clearTimeout = NOOP;\n baseContext.setImmediate = NOOP;\n baseContext.requestAnimationFrame = NOOP;\n baseContext.setInterval = NOOP;\n baseContext.setTimeout = NOOP;\n\n // eslint-disable-next-line guard-for-in,no-restricted-syntax\n for (const key in additionalContext) {\n baseContext[key] = additionalContext[key];\n }\n\n return baseContext;\n}\n\nfunction createHappyDOMWindow() {\n const win = createWindow();\n\n return {\n teardown: () => {\n win.happyDOM.cancelAsync();\n },\n window: win,\n };\n}\n\nfunction createNothing() {\n return {\n teardown: () => {},\n window: undefined,\n };\n}\n\nexport function createVmContext(\n filename: string,\n features: FeatureFlags<'happyDOM'>,\n additionalContext: Partial<vm.Context>,\n overrideContext: StrictOptions['overrideContext'] = (i) => i\n) {\n const isHappyDOMEnabled = isFeatureEnabled(features, 'happyDOM', filename);\n\n const { teardown, window } = isHappyDOMEnabled\n ? createHappyDOMWindow()\n : createNothing();\n const baseContext = createBaseContext(\n window,\n overrideContext(\n {\n __filename: filename,\n ...additionalContext,\n },\n filename\n )\n );\n\n const context = vm.createContext(baseContext);\n\n return {\n context,\n teardown,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,EAAA,GAAAC,uBAAA,CAAAC,OAAA;AAKA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,OAAA,GAAAH,uBAAA,CAAAC,OAAA;AAAqC,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA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ED,QAAQ,CAAC;EAE1E,MAAM;IAAEN,QAAQ;IAAEd;EAAO,CAAC,GAAGuB,iBAAiB,GAC1CV,oBAAoB,CAAC,CAAC,GACtBI,aAAa,CAAC,CAAC;EACnB,MAAMnB,WAAW,GAAGF,iBAAiB,CACnCI,MAAM,EACNsB,eAAe,CACb;IACEG,UAAU,EAAEL,QAAQ;IACpB,GAAGvB;EACL,CAAC,EACDuB,QACF,CACF,CAAC;EAED,MAAMM,OAAO,GAAGhE,EAAE,CAACiE,aAAa,CAAC7B,WAAW,CAAC;EAE7C,OAAO;IACL4B,OAAO;IACPZ;EACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,43 +1,46 @@
1
1
  {
2
2
  "name": "@wyw-in-js/transform",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "dependencies": {
5
- "@babel/core": "^7.23.0",
6
- "@babel/generator": "^7.23.0",
5
+ "@babel/core": "^7.23.5",
6
+ "@babel/generator": "^7.23.5",
7
7
  "@babel/helper-module-imports": "^7.22.15",
8
- "@babel/plugin-transform-modules-commonjs": "^7.23.0",
8
+ "@babel/plugin-transform-modules-commonjs": "^7.23.3",
9
9
  "@babel/template": "^7.22.15",
10
- "@babel/traverse": "^7.23.0",
11
- "@babel/types": "^7.23.0",
10
+ "@babel/traverse": "^7.23.5",
11
+ "@babel/types": "^7.23.5",
12
12
  "babel-merge": "^3.0.0",
13
13
  "cosmiconfig": "^8.0.0",
14
- "find-up": "^5.0.0",
15
14
  "happy-dom": "^12.5.0",
16
15
  "source-map": "^0.7.4",
17
- "stylis": "^3.5.4",
16
+ "stylis": "^4.3.0",
18
17
  "ts-invariant": "^0.10.3",
19
- "@wyw-in-js/processor-utils": "0.1.1",
20
- "@wyw-in-js/shared": "0.1.1"
18
+ "@wyw-in-js/processor-utils": "0.2.0",
19
+ "@wyw-in-js/shared": "0.2.0"
21
20
  },
22
21
  "devDependencies": {
23
- "@babel/plugin-syntax-typescript": "^7.22.5",
24
- "@babel/types": "^7.23.0",
22
+ "@babel/plugin-syntax-typescript": "^7.23.3",
23
+ "@babel/types": "^7.23.5",
25
24
  "@swc/core": "1.3.20",
26
- "@types/babel__core": "^7.20.2",
27
- "@types/babel__generator": "^7.6.5",
28
- "@types/babel__helper-module-imports": "^7.18.1",
29
- "@types/babel__template": "^7.4.2",
30
- "@types/babel__traverse": "^7.20.2",
25
+ "@types/babel__core": "^7.20.5",
26
+ "@types/babel__generator": "^7.6.7",
27
+ "@types/babel__helper-module-imports": "^7.18.3",
28
+ "@types/babel__template": "^7.4.4",
29
+ "@types/babel__traverse": "^7.20.4",
31
30
  "@types/debug": "^4.1.9",
32
31
  "@types/node": "^16.18.55",
32
+ "@types/stylis": "^4.2.4",
33
+ "babel-plugin-istanbul": "^6.1.1",
34
+ "babel-plugin-module-resolver": "^4.1.0",
33
35
  "dedent": "^1.5.1",
34
36
  "esbuild": "^0.15.16",
37
+ "glob": "^10.3.10",
35
38
  "strip-ansi": "^5.2.0",
36
39
  "typescript": "^5.2.2",
37
- "@wyw-in-js/babel-config": "0.1.1",
38
- "@wyw-in-js/eslint-config": "0.1.1",
39
- "@wyw-in-js/jest-preset": "0.1.1",
40
- "@wyw-in-js/ts-config": "0.1.1"
40
+ "@wyw-in-js/babel-config": "0.2.0",
41
+ "@wyw-in-js/eslint-config": "0.2.0",
42
+ "@wyw-in-js/jest-preset": "0.2.0",
43
+ "@wyw-in-js/ts-config": "0.2.0"
41
44
  },
42
45
  "engines": {
43
46
  "node": ">=16.0.0"
package/types/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  export { slugify } from '@wyw-in-js/shared';
2
2
  export { createFileReporter } from './debug/fileReporter';
3
3
  export type { IFileReporterOptions } from './debug/fileReporter';
4
+ export { default as babelTransformPlugin } from './plugins/babel-transform';
4
5
  export { default as preeval } from './plugins/preeval';
5
6
  export { getTransformMetadata, withTransformMetadata, } from './utils/TransformMetadata';
6
7
  export type { WYWTransformMetadata } from './utils/TransformMetadata';
7
8
  export { Module, DefaultModuleImplementation } from './module';
9
+ export { default as shaker } from './shaker';
8
10
  export { transform } from './transform';
9
11
  export { isUnprocessedEntrypointError, UnprocessedEntrypointError, } from './transform/actions/UnprocessedEntrypointError';
10
12
  export * from './types';
@@ -17,10 +19,11 @@ export { prepareCode } from './transform/generators/transform';
17
19
  export { Entrypoint } from './transform/Entrypoint';
18
20
  export { transformUrl } from './transform/generators/extract';
19
21
  export { asyncResolveImports, syncResolveImports, } from './transform/generators/resolveImports';
20
- export { loadLinariaOptions } from './transform/helpers/loadLinariaOptions';
22
+ export { loadWywOptions } from './transform/helpers/loadWywOptions';
21
23
  export { withDefaultServices } from './transform/helpers/withDefaultServices';
22
24
  export type { Services } from './transform/types';
23
- export type { EventEmitter } from './utils/EventEmitter';
25
+ export { EventEmitter } from './utils/EventEmitter';
26
+ export type { EntrypointEvent, OnEvent, OnActionStartArgs, OnActionFinishArgs, } from './utils/EventEmitter';
24
27
  export { isNode } from './utils/isNode';
25
28
  export { getFileIdx } from './utils/getFileIdx';
26
29
  export { getTagProcessor } from './utils/getTagProcessor';
package/types/index.js CHANGED
@@ -17,11 +17,13 @@ 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.TransformCacheCollection = exports.processTemplateExpression = exports.peek = exports.getVisitorKeys = exports.getTagProcessor = exports.getFileIdx = exports.isNode = exports.withDefaultServices = exports.loadLinariaOptions = exports.syncResolveImports = exports.asyncResolveImports = exports.transformUrl = exports.Entrypoint = exports.prepareCode = exports.baseHandlers = exports.parseFile = exports.EvaluatedEntrypoint = exports.UnprocessedEntrypointError = exports.isUnprocessedEntrypointError = exports.transform = exports.DefaultModuleImplementation = exports.Module = exports.withTransformMetadata = exports.getTransformMetadata = exports.preeval = exports.createFileReporter = exports.slugify = void 0;
20
+ exports.TransformCacheCollection = exports.processTemplateExpression = exports.peek = exports.getVisitorKeys = exports.getTagProcessor = 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");
24
24
  Object.defineProperty(exports, "createFileReporter", { enumerable: true, get: function () { return fileReporter_1.createFileReporter; } });
25
+ var babel_transform_1 = require("./plugins/babel-transform");
26
+ Object.defineProperty(exports, "babelTransformPlugin", { enumerable: true, get: function () { return __importDefault(babel_transform_1).default; } });
25
27
  var preeval_1 = require("./plugins/preeval");
26
28
  Object.defineProperty(exports, "preeval", { enumerable: true, get: function () { return __importDefault(preeval_1).default; } });
27
29
  var TransformMetadata_1 = require("./utils/TransformMetadata");
@@ -30,6 +32,8 @@ Object.defineProperty(exports, "withTransformMetadata", { enumerable: true, get:
30
32
  var module_1 = require("./module");
31
33
  Object.defineProperty(exports, "Module", { enumerable: true, get: function () { return module_1.Module; } });
32
34
  Object.defineProperty(exports, "DefaultModuleImplementation", { enumerable: true, get: function () { return module_1.DefaultModuleImplementation; } });
35
+ var shaker_1 = require("./shaker");
36
+ Object.defineProperty(exports, "shaker", { enumerable: true, get: function () { return __importDefault(shaker_1).default; } });
33
37
  var transform_1 = require("./transform");
34
38
  Object.defineProperty(exports, "transform", { enumerable: true, get: function () { return transform_1.transform; } });
35
39
  var UnprocessedEntrypointError_1 = require("./transform/actions/UnprocessedEntrypointError");
@@ -51,10 +55,12 @@ Object.defineProperty(exports, "transformUrl", { enumerable: true, get: function
51
55
  var resolveImports_1 = require("./transform/generators/resolveImports");
52
56
  Object.defineProperty(exports, "asyncResolveImports", { enumerable: true, get: function () { return resolveImports_1.asyncResolveImports; } });
53
57
  Object.defineProperty(exports, "syncResolveImports", { enumerable: true, get: function () { return resolveImports_1.syncResolveImports; } });
54
- var loadLinariaOptions_1 = require("./transform/helpers/loadLinariaOptions");
55
- Object.defineProperty(exports, "loadLinariaOptions", { enumerable: true, get: function () { return loadLinariaOptions_1.loadLinariaOptions; } });
58
+ var loadWywOptions_1 = require("./transform/helpers/loadWywOptions");
59
+ Object.defineProperty(exports, "loadWywOptions", { enumerable: true, get: function () { return loadWywOptions_1.loadWywOptions; } });
56
60
  var withDefaultServices_1 = require("./transform/helpers/withDefaultServices");
57
61
  Object.defineProperty(exports, "withDefaultServices", { enumerable: true, get: function () { return withDefaultServices_1.withDefaultServices; } });
62
+ var EventEmitter_1 = require("./utils/EventEmitter");
63
+ Object.defineProperty(exports, "EventEmitter", { enumerable: true, get: function () { return EventEmitter_1.EventEmitter; } });
58
64
  var isNode_1 = require("./utils/isNode");
59
65
  Object.defineProperty(exports, "isNode", { enumerable: true, get: function () { return isNode_1.isNode; } });
60
66
  var getFileIdx_1 = require("./utils/getFileIdx");
@@ -12,7 +12,7 @@ function loadBabelOptions(babel, filename, overrides = empty) {
12
12
  ...overrides,
13
13
  filename,
14
14
  caller: {
15
- name: 'linaria',
15
+ name: 'wyw-in-js',
16
16
  // Indicates for @babel/preset-env to support all ESM syntax and avoid transforms before it's needed
17
17
  supportsStaticESM: true,
18
18
  supportsDynamicImport: true,
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const shared_1 = require("@wyw-in-js/shared");
4
+ const loadWywOptions_1 = require("../transform/helpers/loadWywOptions");
4
5
  const cache_1 = require("../cache");
5
6
  const transform_1 = require("../transform");
6
- const loadLinariaOptions_1 = require("../transform/helpers/loadLinariaOptions");
7
7
  const collector_1 = require("./collector");
8
8
  function babelTransform(babel, options) {
9
9
  const cache = new cache_1.TransformCacheCollection();
@@ -26,7 +26,7 @@ function babelTransform(babel, options) {
26
26
  };
27
27
  }
28
28
  debug('start %s', file.opts.filename);
29
- const pluginOptions = (0, loadLinariaOptions_1.loadLinariaOptions)(options);
29
+ const pluginOptions = (0, loadWywOptions_1.loadWywOptions)(options);
30
30
  (0, transform_1.transformSync)({
31
31
  babel,
32
32
  cache,
@@ -30,8 +30,8 @@ function collector(file, options, values) {
30
30
  // We didn't find any processors.
31
31
  return processors;
32
32
  }
33
- // We can remove __linariaPreval export and all related code
34
- const prevalExport = file.path.scope.getData('__linariaPreval')?.findParent((p) => p.isExpressionStatement());
33
+ // We can remove __wywPreval export and all related code
34
+ const prevalExport = file.path.scope.getData('__wywPreval')?.findParent((p) => p.isExpressionStatement());
35
35
  if (prevalExport) {
36
36
  (0, scopeHelpers_1.removeWithRelated)([prevalExport]);
37
37
  }
@@ -47,10 +47,10 @@ function collectorPlugin(babel, options) {
47
47
  debug('start %s', file.opts.filename);
48
48
  const processors = collector(file, options, values);
49
49
  if (processors.length === 0) {
50
- // We didn't find any Linaria template literals.
50
+ // We didn't find any wyw-in-js template literals.
51
51
  return;
52
52
  }
53
- this.file.metadata.linaria = {
53
+ this.file.metadata.wywInJS = {
54
54
  processors,
55
55
  replacements: [],
56
56
  rules: {},
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.preeval = void 0;
4
4
  const shared_1 = require("@wyw-in-js/shared");
5
5
  const EventEmitter_1 = require("../utils/EventEmitter");
6
- const addIdentifierToLinariaPreval_1 = require("../utils/addIdentifierToLinariaPreval");
6
+ const addIdentifierToWywPreval_1 = require("../utils/addIdentifierToWywPreval");
7
7
  const getFileIdx_1 = require("../utils/getFileIdx");
8
8
  const processTemplateExpression_1 = require("../utils/processTemplateExpression");
9
9
  const removeDangerousCode_1 = require("../utils/removeDangerousCode");
@@ -24,7 +24,7 @@ function preeval(babel, { eventEmitter = EventEmitter_1.EventEmitter.dummy, ...o
24
24
  (0, processTemplateExpression_1.processTemplateExpression)(p, file.opts, options, (processor) => {
25
25
  processor.dependencies.forEach((dependency) => {
26
26
  if (dependency.ex.type === 'Identifier') {
27
- (0, addIdentifierToLinariaPreval_1.addIdentifierToLinariaPreval)(rootScope, dependency.ex.name);
27
+ (0, addIdentifierToWywPreval_1.addIdentifierToWywPreval)(rootScope, dependency.ex.name);
28
28
  }
29
29
  });
30
30
  processor.doEvaltimeReplacement();
@@ -45,23 +45,23 @@ function preeval(babel, { eventEmitter = EventEmitter_1.EventEmitter.dummy, ...o
45
45
  .extend((0, getFileIdx_1.getFileIdx)(file.opts.filename));
46
46
  (0, traversalCache_1.invalidateTraversalCache)(file.path);
47
47
  if (this.processors.length === 0) {
48
- log('end', "We didn't find any Linaria template literals");
49
- // We didn't find any Linaria template literals.
48
+ log('end', "We didn't find any wyw-in-js template literals");
49
+ // We didn't find any wyw-in-js template literals.
50
50
  return;
51
51
  }
52
- this.file.metadata.linaria = {
52
+ this.file.metadata.wywInJS = {
53
53
  processors: this.processors,
54
54
  replacements: [],
55
55
  rules: {},
56
56
  dependencies: [],
57
57
  };
58
- const linariaPreval = file.path.getData('__linariaPreval');
59
- if (!linariaPreval) {
60
- // Event if there is no dependencies, we still need to add __linariaPreval
61
- const linariaExport = t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier('exports'), t.identifier('__linariaPreval')), t.objectExpression([])));
62
- file.path.pushContainer('body', linariaExport);
58
+ const wywPreval = file.path.getData('__wywPreval');
59
+ if (!wywPreval) {
60
+ // Event if there is no dependencies, we still need to add __wywPreval
61
+ const wywExport = t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier('exports'), t.identifier('__wywPreval')), t.objectExpression([])));
62
+ file.path.pushContainer('body', wywExport);
63
63
  }
64
- log('end', '__linariaPreval has been added');
64
+ log('end', '__wywPreval has been added');
65
65
  },
66
66
  };
67
67
  }
@@ -112,11 +112,11 @@ function shakerPlugin(babel, { keepSideEffects = false, ifUnknownExport = 'skip-
112
112
  }
113
113
  }
114
114
  });
115
- const hasLinariaPreval = exports.__linariaPreval !== undefined;
115
+ const hasWywPreval = exports.__wywPreval !== undefined;
116
116
  const hasDefault = exports.default !== undefined;
117
- // If __linariaPreval is not exported, we can remove it from onlyExports
118
- if (onlyExportsSet.has('__linariaPreval') && !hasLinariaPreval) {
119
- onlyExportsSet.delete('__linariaPreval');
117
+ // If __wywPreval is not exported, we can remove it from onlyExports
118
+ if (onlyExportsSet.has('__wywPreval') && !hasWywPreval) {
119
+ onlyExportsSet.delete('__wywPreval');
120
120
  }
121
121
  if (onlyExportsSet.size === 0) {
122
122
  // Fast-lane: if there are no exports to keep, we can just shake out the whole file
@@ -289,7 +289,7 @@ function shakerPlugin(babel, { keepSideEffects = false, ifUnknownExport = 'skip-
289
289
  this.reexports.forEach(addImport);
290
290
  log('end', `remaining imports: %O`, imports);
291
291
  // eslint-disable-next-line no-param-reassign
292
- file.metadata.linariaEvaluator = {
292
+ file.metadata.wywEvaluator = {
293
293
  imports,
294
294
  };
295
295
  (0, traversalCache_1.invalidateTraversalCache)(file.path);
package/types/shaker.js CHANGED
@@ -47,7 +47,7 @@ const shaker = (evalConfig, ast, code, { highPriorityPlugins, ...config }, babel
47
47
  const transformOptions = {
48
48
  ...evalConfig,
49
49
  caller: {
50
- name: 'linaria',
50
+ name: 'wyw-in-js',
51
51
  },
52
52
  plugins,
53
53
  };
@@ -58,7 +58,7 @@ const shaker = (evalConfig, ast, code, { highPriorityPlugins, ...config }, babel
58
58
  return [
59
59
  transformed.ast,
60
60
  transformed.code ?? '',
61
- transformed.metadata.linariaEvaluator.imports,
61
+ transformed.metadata.wywEvaluator.imports,
62
62
  ];
63
63
  };
64
64
  exports.default = shaker;
@@ -43,7 +43,7 @@ export declare class Entrypoint extends BaseEntrypoint {
43
43
  createEvaluated(): EvaluatedEntrypoint;
44
44
  getDependency(name: string): IEntrypointDependency | undefined;
45
45
  getResolveTask(name: string): Promise<IEntrypointDependency> | undefined;
46
- hasLinariaMetadata(): boolean;
46
+ hasWywMetadata(): boolean;
47
47
  onSupersede(callback: (newEntrypoint: Entrypoint) => void): () => void;
48
48
  setTransformResult(res: ITransformFileResult | null): void;
49
49
  private supersede;
@@ -68,9 +68,9 @@ function buildConfigs(services, name, pluginOptions, babelOptions) {
68
68
  if (parseHasModuleResolver && !rawHasModuleResolver) {
69
69
  if (!moduleResolverWarned) {
70
70
  // eslint-disable-next-line no-console
71
- console.warn(`[linaria] ${name} has a module-resolver plugin in its babelrc, but it is not present ` +
72
- `in the babelOptions for the linaria plugin. This works for now but will be an error in the future. ` +
73
- `Please add the module-resolver plugin to the babelOptions for the linaria plugin.`);
71
+ console.warn(`[wyw-in-js] ${name} has a module-resolver plugin in its babelrc, but it is not present ` +
72
+ `in the babelOptions for the wyw-in-js plugin. This works for now but will be an error in the future. ` +
73
+ `Please add the module-resolver plugin to the babelOptions for the wyw-in-js plugin.`);
74
74
  moduleResolverWarned = true;
75
75
  }
76
76
  rawConfig.plugins = [
@@ -29,7 +29,7 @@ class Entrypoint extends BaseEntrypoint_1.BaseEntrypoint {
29
29
  loadedAndParsed;
30
30
  onSupersedeHandlers = [];
31
31
  actionsCache = new Map();
32
- #hasLinariaMetadata = false;
32
+ #hasWywMetadata = false;
33
33
  #supersededWith = null;
34
34
  #transformResultCode = null;
35
35
  constructor(services, parents, initialCode, name, only, exports, evaluatedOnly, loadedAndParsed, resolveTasks = new Map(), dependencies = new Map(), generation = 1) {
@@ -182,8 +182,8 @@ class Entrypoint extends BaseEntrypoint_1.BaseEntrypoint {
182
182
  getResolveTask(name) {
183
183
  return this.resolveTasks.get(name);
184
184
  }
185
- hasLinariaMetadata() {
186
- return this.#hasLinariaMetadata;
185
+ hasWywMetadata() {
186
+ return this.#hasWywMetadata;
187
187
  }
188
188
  onSupersede(callback) {
189
189
  if (this.#supersededWith) {
@@ -199,7 +199,7 @@ class Entrypoint extends BaseEntrypoint_1.BaseEntrypoint {
199
199
  };
200
200
  }
201
201
  setTransformResult(res) {
202
- this.#hasLinariaMetadata = Boolean(res?.metadata);
202
+ this.#hasWywMetadata = Boolean(res?.metadata);
203
203
  this.#transformResultCode = res?.code ?? null;
204
204
  this.services.eventEmitter.entrypointEvent(this.seqId, {
205
205
  isNull: res === null,
@@ -27,7 +27,7 @@ function* collect() {
27
27
  ],
28
28
  ];
29
29
  const transformConfig = (0, buildOptions_1.buildOptions)({
30
- envName: 'linaria',
30
+ envName: 'wyw-in-js',
31
31
  plugins: transformPlugins,
32
32
  sourceMaps: true,
33
33
  sourceFileName: name,