@wyw-in-js/transform 2.0.0-alpha.1 → 2.0.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.
Files changed (44) hide show
  1. package/esm/transform/Entrypoint.types.js.map +1 -1
  2. package/esm/transform/generators/collect.js +1 -0
  3. package/esm/transform/generators/collect.js.map +1 -1
  4. package/esm/transform/generators/resolveStaticOxcValues/prune.js +91 -5
  5. package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -1
  6. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +2 -1
  7. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -1
  8. package/esm/transform/generators/transform.js +1 -0
  9. package/esm/transform/generators/transform.js.map +1 -1
  10. package/esm/utils/EventEmitter.js +13 -0
  11. package/esm/utils/EventEmitter.js.map +1 -1
  12. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js +1 -1
  13. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js.map +1 -1
  14. package/esm/utils/applyOxcProcessors/cleanupRemovals.js +102 -16
  15. package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -1
  16. package/esm/utils/collectOxcExportsAndImports.js +8 -0
  17. package/esm/utils/collectOxcExportsAndImports.js.map +1 -1
  18. package/esm/utils/collectOxcRuntime/types.js.map +1 -1
  19. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js +6 -4
  20. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js.map +1 -1
  21. package/esm/utils/oxc/ast.js +42 -12
  22. package/esm/utils/oxc/ast.js.map +1 -1
  23. package/esm/utils/oxcPreevalTransforms.js +94 -65
  24. package/esm/utils/oxcPreevalTransforms.js.map +1 -1
  25. package/esm/utils/parseOxc.js +6 -1
  26. package/esm/utils/parseOxc.js.map +1 -1
  27. package/package.json +5 -5
  28. package/types/transform/Entrypoint.types.d.ts +1 -0
  29. package/types/transform/generators/collect.js +1 -0
  30. package/types/transform/generators/resolveStaticOxcValues/prune.d.ts +1 -1
  31. package/types/transform/generators/resolveStaticOxcValues/prune.js +96 -4
  32. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +2 -1
  33. package/types/transform/generators/transform.js +1 -0
  34. package/types/utils/EventEmitter.js +13 -0
  35. package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +1 -0
  36. package/types/utils/applyOxcProcessors/applyOxcProcessors.js +3 -1
  37. package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +2 -2
  38. package/types/utils/applyOxcProcessors/cleanupRemovals.js +104 -19
  39. package/types/utils/collectOxcExportsAndImports.js +8 -0
  40. package/types/utils/collectOxcRuntime/types.d.ts +1 -0
  41. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.js +6 -4
  42. package/types/utils/oxc/ast.js +42 -18
  43. package/types/utils/oxcPreevalTransforms.js +97 -74
  44. package/types/utils/parseOxc.js +6 -1
@@ -1 +1 @@
1
- {"mappings":"AAYA,SAAS,mCAAmC;AAC5C,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAiCtC,MAAM,iBAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,mBAAmB,IAAI,IAAI;CAC/B,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,6BAA6B,IAAI,IAAI,CAAC,gBAAgB,eAAe,CAAC;AAC5E,MAAM,yBAAyB,IAAI,IAAI;CAAC;CAAQ;CAAS;CAAU,CAAC;AACpE,MAAM,oBAAoB,IAAI,IAAI,CAChC,qBACA,wBACD,CAAC;AACF,MAAM,qBAAqB;AAC3B,MAAM,6BAA6B;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AACD,MAAM,mBAAmB,CAAC,cAAc,OAAO;AAC/C,MAAM,iCAAiC;AACvC,MAAM,gBAAgB;AACtB,MAAM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AO,OAAO,YAAY,GAAG,KAAK,KAAK,eAAe;IACvD,CAAC;AACF;;EAGF,MAAM,cAAc,UAAU,UAAU,SAAS,MAAM;AACvD,MACE,QAAQ,SAAS,sBACjB,OAAO,WAAW,QAClB,aAAa,SAAS,mBACtB,YAAY,aAAa,QACzB;AACA,gBAAa,KAAK;IAChB,OAAO,YAAY;IACnB,KAAK,YAAY;IACjB,OAAO;IACR,CAAC;AACF;;EAGF,MAAM,mBAAmB,8BACvB,MACA,WACA,qBACD;AACD,MAAI,kBAAkB;AACpB,gBAAa,KAAK,iBAAiB;AACnC;;EAGF,MAAM,eAAe,yBAAyB,UAAU;EACxD,MAAM,QAAQ,eACV,mBAAmB,cAAc,UAAU,GAC3C,mBAAmB,MAAM,UAAU;AACvC,eAAa,KAAK;GAAE,OAAO,MAAM;GAAO,KAAK,MAAM;GAAK,OAAO;GAAI,CAAC;GAEvE;AAED,QAAO,kBAAkB,MAAM,sBAAsB,aAAa,CAAC","names":[],"sources":["../../src/utils/oxcPreevalTransforms.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue */\n\nimport type {\n CallExpression,\n Expression,\n ImportExpression,\n Node,\n Program,\n} from 'oxc-parser';\n\nimport type { CodeRemoverOptions } from '@wyw-in-js/shared';\n\nimport { collectOxcExportsAndImports } from './collectOxcExportsAndImports';\nimport { EventEmitter } from './EventEmitter';\nimport { parseOxcProgramCached } from './parseOxc';\n\ntype AnyNode = Node & Record<string, unknown>;\n\ntype Replacement = {\n end: number;\n start: number;\n value: string;\n};\n\ntype Scope = {\n bindings: Map<string, Expression | null>;\n key: string;\n names: Set<string>;\n parent: Scope | null;\n};\n\ntype ImportBinding = {\n imported: string | 'default' | '*';\n local: string;\n source: string;\n};\n\ntype OxcFunctionLikeNode = Node & {\n async: boolean;\n body: Node;\n id?: { name: string } | null;\n type:\n | 'ArrowFunctionExpression'\n | 'FunctionDeclaration'\n | 'FunctionExpression';\n};\n\nconst ssrCheckFields = new Set([\n 'document',\n 'location',\n 'navigator',\n 'sessionStorage',\n 'localStorage',\n 'window',\n]);\n\nconst forbiddenGlobals = new Set([\n ...ssrCheckFields,\n '$RefreshReg$',\n '$RefreshSig$',\n 'XMLHttpRequest',\n 'clearImmediate',\n 'clearInterval',\n 'clearTimeout',\n 'fetch',\n 'navigator',\n 'setImmediate',\n 'setInterval',\n 'setTimeout',\n]);\n\nconst alwaysForbiddenIdentifiers = new Set(['$RefreshReg$', '$RefreshSig$']);\nconst promiseCallbackMethods = new Set(['then', 'catch', 'finally']);\nconst jsxRuntimeSources = new Set([\n 'react/jsx-runtime',\n 'react/jsx-dev-runtime',\n]);\nconst defaultPlaceholder = '...';\nconst defaultReactComponentTypes = [\n 'ExoticComponent',\n 'FC',\n 'ForwardRefExoticComponent',\n 'FunctionComponent',\n 'LazyExoticComponent',\n 'MemoExoticComponent',\n 'NamedExoticComponent',\n];\nconst defaultReactHocs = ['forwardRef', 'memo'];\nconst generatedProcessorHelperNameRe = /^_exp\\d*$/;\nconst requireCallRe = /\\brequire\\s*\\(/;\nconst windowTokenRe = /\\bwindow\\b/;\nconst removableOwnerTypes = new Set([\n 'DoWhileStatement',\n 'ExpressionStatement',\n 'ForInStatement',\n 'ForOfStatement',\n 'ForStatement',\n 'FunctionDeclaration',\n 'IfStatement',\n 'PropertyDefinition',\n 'ReturnStatement',\n 'VariableDeclaration',\n 'WhileStatement',\n]);\nconst importMetaEnvRe = /\\bimport\\s*\\.\\s*meta\\s*\\.\\s*env\\b/;\n\nconst createScope = (parent: Scope | null, key: string): Scope => ({\n bindings: new Map(),\n key,\n names: new Set(),\n parent,\n});\n\nconst createsScope = (node: Node): boolean =>\n node.type === 'Program' ||\n node.type === 'BlockStatement' ||\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression';\n\nconst hasBinding = (scope: Scope, name: string): boolean => {\n let current: Scope | null = scope;\n while (current) {\n if (current.names.has(name)) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n};\n\nconst getBindingKey = (scope: Scope, name: string): string | null => {\n let current: Scope | null = scope;\n while (current) {\n if (current.names.has(name)) {\n return `${current.key}\\0${name}`;\n }\n\n current = current.parent;\n }\n\n return null;\n};\n\nconst getStaticBinding = (\n scope: Scope,\n name: string\n): Expression | null | undefined => {\n let current: Scope | null = scope;\n while (current) {\n if (current.bindings.has(name)) {\n return current.bindings.get(name);\n }\n\n current = current.parent;\n }\n\n return undefined;\n};\n\nconst isFileLikeRequireSpecifier = (value: string): boolean =>\n value.startsWith('.') || value.startsWith('/') || value.startsWith('file:');\n\nconst isNode = (value: unknown): value is Node =>\n !!value &&\n typeof value === 'object' &&\n 'type' in value &&\n typeof (value as { type?: unknown }).type === 'string';\n\nconst getChildren = (node: Node): Node[] => {\n const result: Node[] = [];\n const record = node as AnyNode;\n\n Object.keys(record).forEach((key) => {\n if (key === 'type' || key === 'start' || key === 'end' || key === 'range') {\n return;\n }\n\n const value = record[key];\n if (isNode(value)) {\n result.push(value);\n return;\n }\n\n if (Array.isArray(value)) {\n value.forEach((item) => {\n if (isNode(item)) {\n result.push(item);\n }\n });\n }\n });\n\n return result;\n};\n\nconst parseOxc = (code: string, filename: string): Program => {\n return parseOxcProgramCached(filename, code, 'unambiguous');\n};\n\nconst unwrapExpression = (node: Expression): Expression => {\n if (\n node.type === 'TSAsExpression' ||\n node.type === 'TSSatisfiesExpression' ||\n node.type === 'TSNonNullExpression' ||\n node.type === 'TSTypeAssertion' ||\n node.type === 'ParenthesizedExpression'\n ) {\n return unwrapExpression(node.expression);\n }\n\n return node;\n};\n\nconst getMemberPropertyName = (node: Node): string | null => {\n if (node.type !== 'MemberExpression') {\n return null;\n }\n\n if (node.computed) {\n return node.property.type === 'Literal' &&\n typeof node.property.value === 'string'\n ? node.property.value\n : null;\n }\n\n return node.property.type === 'Identifier' ? node.property.name : null;\n};\n\nconst isStringLikeExpression = (node: Expression): boolean => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal' && typeof expression.value === 'string') {\n return true;\n }\n\n if (expression.type === 'TemplateLiteral') {\n return true;\n }\n\n if (expression.type === 'BinaryExpression' && expression.operator === '+') {\n return (\n isStringLikeExpression(expression.left) ||\n isStringLikeExpression(expression.right)\n );\n }\n\n if (\n expression.type === 'CallExpression' &&\n expression.callee.type === 'MemberExpression' &&\n getMemberPropertyName(expression.callee) === 'concat'\n ) {\n return isStringLikeExpression(expression.callee.object);\n }\n\n return false;\n};\n\nconst templateLiteralToConcat = (code: string, node: Expression): string => {\n if (node.type !== 'TemplateLiteral' || node.expressions.length === 0) {\n return code.slice(node.start, node.end);\n }\n\n const parts: string[] = [];\n node.quasis.forEach((quasi, index) => {\n const cooked = quasi.value.cooked ?? quasi.value.raw;\n if (cooked !== '') {\n parts.push(JSON.stringify(cooked));\n }\n\n const expression = node.expressions[index];\n if (expression) {\n parts.push(code.slice(expression.start, expression.end));\n }\n });\n\n return parts.length > 0 ? parts.join(' + ') : '\"\"';\n};\n\nconst dynamicImportArgumentCode = (code: string, node: Expression): string => {\n if (node.type === 'TemplateLiteral') {\n return templateLiteralToConcat(code, node);\n }\n\n return code.slice(node.start, node.end);\n};\n\nconst evaluateStaticValue = (\n node: Expression,\n scope: Scope,\n seen = new Set<string>()\n): unknown | undefined => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal') {\n return expression.value;\n }\n\n if (expression.type === 'TemplateLiteral') {\n let result = '';\n\n for (let idx = 0; idx < expression.quasis.length; idx += 1) {\n result += expression.quasis[idx]?.value.cooked ?? '';\n\n const nextExpression = expression.expressions[idx];\n if (!nextExpression) {\n continue;\n }\n\n const value = evaluateStaticValue(nextExpression, scope, seen);\n if (\n value === undefined ||\n (typeof value !== 'string' && typeof value !== 'number')\n ) {\n return undefined;\n }\n\n result += String(value);\n }\n\n return result;\n }\n\n if (expression.type === 'Identifier') {\n if (seen.has(expression.name)) {\n return undefined;\n }\n\n const binding = getStaticBinding(scope, expression.name);\n if (!binding) {\n return undefined;\n }\n\n return evaluateStaticValue(\n binding,\n scope,\n new Set([...seen, expression.name])\n );\n }\n\n if (expression.type === 'BinaryExpression' && expression.operator === '+') {\n const left = evaluateStaticValue(expression.left, scope, seen);\n const right = evaluateStaticValue(expression.right, scope, seen);\n\n if (left === undefined || right === undefined) {\n return undefined;\n }\n\n if (typeof left === 'number' && typeof right === 'number') {\n return left + right;\n }\n\n if (\n (typeof left === 'string' || typeof left === 'number') &&\n (typeof right === 'string' || typeof right === 'number')\n ) {\n return `${left}${right}`;\n }\n }\n\n if (\n expression.type === 'CallExpression' &&\n expression.callee.type === 'MemberExpression'\n ) {\n const objectValue = evaluateStaticValue(\n expression.callee.object,\n scope,\n seen\n );\n const propertyName = getMemberPropertyName(expression.callee);\n if (!propertyName) {\n return undefined;\n }\n\n if (typeof objectValue === 'string') {\n if (propertyName === 'toLowerCase' && expression.arguments.length === 0) {\n return objectValue.toLowerCase();\n }\n\n if (propertyName === 'toUpperCase' && expression.arguments.length === 0) {\n return objectValue.toUpperCase();\n }\n\n if (propertyName === 'trim' && expression.arguments.length === 0) {\n return objectValue.trim();\n }\n\n if (propertyName === 'concat') {\n const args = expression.arguments.map((argument) =>\n argument.type === 'SpreadElement'\n ? undefined\n : evaluateStaticValue(argument, scope, seen)\n );\n if (\n args.some((value) => value === undefined) ||\n args.some(\n (value) => typeof value !== 'string' && typeof value !== 'number'\n )\n ) {\n return undefined;\n }\n\n return objectValue.concat(...args.map((value) => String(value)));\n }\n }\n }\n\n return undefined;\n};\n\nconst isLiteralRequireArg = (node: Expression): boolean => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal' && typeof expression.value === 'string') {\n return true;\n }\n\n if (\n expression.type === 'TemplateLiteral' &&\n expression.expressions.length === 0\n ) {\n return true;\n }\n\n return false;\n};\n\nconst applyReplacements = (\n code: string,\n replacements: Replacement[]\n): string => {\n let result = code;\n replacements\n .sort((a, b) => b.start - a.start)\n .forEach((replacement) => {\n result =\n result.slice(0, replacement.start) +\n replacement.value +\n result.slice(replacement.end);\n });\n\n return result;\n};\n\nconst isIdentifierNamed = (value: unknown, name: string): boolean =>\n isNode(value) && value.type === 'Identifier' && value.name === name;\n\nconst isImportMeta = (node: unknown): boolean => {\n if (!isNode(node) || node.type !== 'MetaProperty') {\n return false;\n }\n\n const metaProperty = node as AnyNode;\n return (\n isIdentifierNamed(metaProperty.meta, 'import') &&\n isIdentifierNamed(metaProperty.property, 'meta')\n );\n};\n\nconst isImportMetaEnv = (node: Node): boolean => {\n if (node.type !== 'MemberExpression') {\n return false;\n }\n\n if (node.computed || !isIdentifierNamed(node.property, 'env')) {\n return false;\n }\n\n return isImportMeta(node.object);\n};\n\nconst collectBindingNames = (node: Node): string[] => {\n if (node.type === 'Identifier') {\n return [node.name];\n }\n\n if (node.type === 'RestElement') {\n return collectBindingNames(node.argument);\n }\n\n if (node.type === 'AssignmentPattern') {\n return collectBindingNames(node.left);\n }\n\n if (node.type === 'ObjectPattern') {\n return node.properties.flatMap((property) =>\n property.type === 'RestElement'\n ? collectBindingNames(property.argument)\n : collectBindingNames(property.value)\n );\n }\n\n if (node.type === 'ArrayPattern') {\n return node.elements.flatMap((element) =>\n element ? collectBindingNames(element) : []\n );\n }\n\n if (node.type === 'TSParameterProperty') {\n return collectBindingNames(node.parameter);\n }\n\n return [];\n};\n\nconst predeclareScopeNames = (node: Node, scope: Scope): void => {\n if (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n if (node.type !== 'ArrowFunctionExpression' && node.id) {\n scope.names.add(node.id.name);\n }\n\n node.params.forEach((param) => {\n collectBindingNames(param).forEach((name) => {\n scope.names.add(name);\n });\n });\n }\n\n const visitScopeDescendants = (child: Node): void => {\n if (child.type === 'VariableDeclarator') {\n collectBindingNames(child.id).forEach((name) => {\n scope.names.add(name);\n });\n } else if (child.type === 'FunctionDeclaration' && child.id) {\n scope.names.add(child.id.name);\n } else if (child.type === 'ClassDeclaration' && child.id) {\n scope.names.add(child.id.name);\n } else if (\n child.type === 'ImportDefaultSpecifier' ||\n child.type === 'ImportNamespaceSpecifier' ||\n child.type === 'ImportSpecifier'\n ) {\n scope.names.add(child.local.name);\n }\n\n if (createsScope(child)) {\n return;\n }\n\n getChildren(child).forEach(visitScopeDescendants);\n };\n\n getChildren(node).forEach(visitScopeDescendants);\n};\n\nconst declareBindings = (node: Node, scope: Scope): void => {\n if (node.type === 'VariableDeclarator') {\n const names = collectBindingNames(node.id);\n names.forEach((name) => {\n scope.names.add(name);\n scope.bindings.set(name, null);\n });\n\n if (node.id.type === 'Identifier' && node.init) {\n scope.bindings.set(node.id.name, node.init);\n }\n return;\n }\n\n if (node.type === 'FunctionDeclaration' && node.id) {\n scope.names.add(node.id.name);\n scope.bindings.set(node.id.name, null);\n }\n\n if (node.type === 'ClassDeclaration' && node.id) {\n scope.names.add(node.id.name);\n scope.bindings.set(node.id.name, null);\n return;\n }\n\n if (\n node.type === 'ImportDefaultSpecifier' ||\n node.type === 'ImportNamespaceSpecifier' ||\n node.type === 'ImportSpecifier'\n ) {\n scope.names.add(node.local.name);\n scope.bindings.set(node.local.name, null);\n return;\n }\n\n if (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n node.params.forEach((param) => {\n collectBindingNames(param).forEach((name) => {\n scope.names.add(name);\n scope.bindings.set(name, null);\n });\n });\n }\n};\n\nconst visit = (\n node: Node,\n scope: Scope,\n enter: (\n node: Node,\n scope: Scope,\n parent: Node | null,\n ancestors: Node[]\n ) => void,\n parent: Node | null = null,\n ancestors: Node[] = []\n): void => {\n let currentScope = scope;\n if (createsScope(node)) {\n currentScope = createScope(scope, `${node.type}:${node.start}:${node.end}`);\n predeclareScopeNames(node, currentScope);\n }\n\n declareBindings(node, currentScope);\n enter(node, currentScope, parent, ancestors);\n\n getChildren(node).forEach((child) =>\n visit(child, currentScope, enter, node, [...ancestors, node])\n );\n};\n\nexport const replaceImportMetaEnvWithOxc = (\n code: string,\n filename: string\n): string => {\n if (!importMetaEnvRe.test(code)) {\n return code;\n }\n\n const replacements: Replacement[] = [];\n\n visit(parseOxc(code, filename), createScope(null, 'root'), (node) => {\n if (!isImportMetaEnv(node)) {\n return;\n }\n\n replacements.push({\n end: node.end,\n start: node.start,\n value: '__wyw_import_meta_env',\n });\n });\n\n return applyReplacements(code, replacements);\n};\n\ntype CombinedSyntaxRewriteOptions = {\n addRequireFallback: boolean;\n eventEmitter?: EventEmitter;\n rewriteDynamicImports: boolean;\n};\n\ntype RequireFallbackCandidate = {\n call: CallExpression;\n scope: Scope;\n};\n\nfunction collectDynamicImportAndRequireFallbackReplacements(\n code: string,\n filename: string,\n options: CombinedSyntaxRewriteOptions\n): Replacement[] {\n const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;\n const dynamicImportCandidates: ImportExpression[] = [];\n const requireFallbackCandidates: RequireFallbackCandidate[] = [];\n\n eventEmitter.perf(\n 'transform:preeval:dynamicImportRequireFallback:scan',\n () => {\n visit(\n parseOxc(code, filename),\n createScope(null, 'root'),\n (node, scope) => {\n if (\n options.rewriteDynamicImports &&\n node.type === 'ImportExpression'\n ) {\n dynamicImportCandidates.push(node as ImportExpression);\n }\n\n if (!options.addRequireFallback || node.type !== 'CallExpression') {\n return;\n }\n\n const call = node as CallExpression;\n if (\n call.callee.type !== 'Identifier' ||\n call.callee.name !== 'require' ||\n hasBinding(scope, 'require') ||\n call.arguments.length !== 1\n ) {\n return;\n }\n\n const [firstArg] = call.arguments;\n if (\n !firstArg ||\n firstArg.type === 'SpreadElement' ||\n isLiteralRequireArg(firstArg)\n ) {\n return;\n }\n\n requireFallbackCandidates.push({\n call,\n scope,\n });\n }\n );\n }\n );\n\n const replacements: Replacement[] = [];\n\n eventEmitter.perf('transform:preeval:dynamicImport', () => {\n dynamicImportCandidates.forEach((importExpression) => {\n const argument = importExpression.source;\n const nextArgument = isStringLikeExpression(argument)\n ? unwrapExpression(argument)\n : argument;\n\n replacements.push({\n end: importExpression.end,\n start: importExpression.start,\n value: `__wyw_dynamic_import(${dynamicImportArgumentCode(\n code,\n nextArgument\n )})`,\n });\n });\n });\n\n eventEmitter.perf('transform:preeval:requireFallback', () => {\n requireFallbackCandidates.forEach(({ call, scope }) => {\n const [firstArg] = call.arguments;\n if (!firstArg || firstArg.type === 'SpreadElement') {\n return;\n }\n\n const staticValue = evaluateStaticValue(firstArg, scope);\n if (\n typeof staticValue === 'string' &&\n isFileLikeRequireSpecifier(staticValue)\n ) {\n replacements.push({\n end: firstArg.end,\n start: firstArg.start,\n value: JSON.stringify(staticValue),\n });\n return;\n }\n\n replacements.push({\n end: firstArg.end,\n start: firstArg.end,\n value: ', true',\n });\n });\n });\n\n return replacements;\n}\n\nexport const rewriteDynamicImportsWithOxc = (\n code: string,\n filename: string\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n {\n addRequireFallback: false,\n rewriteDynamicImports: true,\n }\n );\n\n return applyReplacements(code, replacements);\n};\n\nexport const addRequireFallbackWithOxc = (\n code: string,\n filename: string\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n {\n addRequireFallback: true,\n rewriteDynamicImports: false,\n }\n );\n\n return applyReplacements(code, replacements);\n};\n\nexport const rewriteDynamicImportsAndAddRequireFallbackWithOxc = (\n code: string,\n filename: string,\n options: CombinedSyntaxRewriteOptions\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n options\n );\n\n return applyReplacements(code, replacements);\n};\n\nconst isBindingPosition = (node: Node, parent: Node | null): boolean => {\n if (!parent) {\n return false;\n }\n\n if (parent.type === 'VariableDeclarator' && parent.id === node) {\n return true;\n }\n\n if (\n (parent.type === 'FunctionDeclaration' ||\n parent.type === 'FunctionExpression' ||\n parent.type === 'ClassDeclaration' ||\n parent.type === 'ClassExpression') &&\n parent.id === node\n ) {\n return true;\n }\n\n if (\n parent.type === 'ImportSpecifier' &&\n (parent.local === node || parent.imported === node)\n ) {\n return true;\n }\n\n if (\n (parent.type === 'ImportDefaultSpecifier' ||\n parent.type === 'ImportNamespaceSpecifier') &&\n parent.local === node\n ) {\n return true;\n }\n\n if (\n parent.type === 'ExportSpecifier' &&\n (parent.local === node || parent.exported === node)\n ) {\n return true;\n }\n\n return false;\n};\n\nconst isPropertyOnlyIdentifier = (node: Node, parent: Node | null): boolean => {\n if (!parent) {\n return false;\n }\n\n if (\n parent.type === 'MemberExpression' &&\n !parent.computed &&\n parent.property === node\n ) {\n return true;\n }\n\n if (\n (parent.type === 'Property' ||\n parent.type === 'MethodDefinition' ||\n parent.type === 'PropertyDefinition') &&\n !parent.computed &&\n parent.key === node\n ) {\n return true;\n }\n\n return false;\n};\n\nconst isTypeContext = (ancestors: Node[]): boolean =>\n ancestors.some(\n (ancestor) =>\n ancestor.type.startsWith('TS') || ancestor.type.startsWith('JSDoc')\n );\n\nconst isInsideTypeof = (ancestors: Node[]): boolean =>\n ancestors.some(\n (ancestor) =>\n ancestor.type === 'UnaryExpression' && ancestor.operator === 'typeof'\n );\n\nconst isInsideImportDeclaration = (ancestors: Node[]): boolean =>\n ancestors.some((ancestor) => ancestor.type === 'ImportDeclaration');\n\nfunction findLastAncestor<T extends Node>(\n ancestors: Node[],\n predicate: (ancestor: Node) => ancestor is T\n): T | null;\nfunction findLastAncestor(\n ancestors: Node[],\n predicate: (ancestor: Node) => boolean\n): Node | null;\nfunction findLastAncestor(\n ancestors: Node[],\n predicate: (ancestor: Node) => boolean\n): Node | null {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (predicate(ancestor)) {\n return ancestor;\n }\n }\n\n return null;\n}\n\nconst findRemovableOwner = (node: Node, ancestors: Node[]): Node => {\n let owner: Node = node;\n let ownerAncestorIndex = -1;\n\n if (!removableOwnerTypes.has(node.type)) {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (removableOwnerTypes.has(ancestor.type)) {\n owner = ancestor;\n ownerAncestorIndex = idx;\n break;\n }\n }\n }\n\n const parent =\n ownerAncestorIndex > 0 ? ancestors[ownerAncestorIndex - 1] : null;\n if (\n parent?.type === 'ExportNamedDeclaration' &&\n 'declaration' in parent &&\n parent.declaration === owner\n ) {\n return parent;\n }\n\n return owner;\n};\n\ntype ExportedBindingProtection = {\n start: number;\n end: number;\n value: string;\n};\n\nconst collectReExportedLocalNames = (program: Program): Set<string> => {\n const names = new Set<string>();\n for (const stmt of program.body) {\n if (\n stmt.type !== 'ExportNamedDeclaration' ||\n stmt.declaration ||\n stmt.source\n ) {\n continue;\n }\n for (const spec of stmt.specifiers) {\n if (spec.type === 'ExportSpecifier' && spec.local.type === 'Identifier') {\n names.add(spec.local.name);\n }\n }\n }\n return names;\n};\n\n// When an offending identifier sits inside the value of a top-level export,\n// removing the surrounding declaration would strip the export binding too.\n// ESM linker then fails on consumers' `import { name } from '...'` because the\n// named export no longer exists. To keep the binding alive, replace just the\n// value (declarator init or default-export expression) with `undefined`.\nconst findExportedBindingProtection = (\n node: Node,\n ancestors: Node[],\n reExportedLocalNames: Set<string>\n): ExportedBindingProtection | null => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n\n if (ancestor.type === 'ExportDefaultDeclaration') {\n const decl = ancestor.declaration;\n if (decl && decl !== node && 'start' in decl && 'end' in decl) {\n return { start: decl.start, end: decl.end, value: 'undefined' };\n }\n return null;\n }\n\n if (ancestor.type !== 'VariableDeclarator') {\n continue;\n }\n\n if (\n ancestor.id.type !== 'Identifier' ||\n !ancestor.init ||\n ancestor.init === node\n ) {\n return null;\n }\n\n const varDecl = ancestors[idx - 1];\n const wrapper = ancestors[idx - 2] ?? null;\n\n if (varDecl?.type !== 'VariableDeclaration') {\n return null;\n }\n\n const isDirectExport =\n wrapper?.type === 'ExportNamedDeclaration' &&\n wrapper.declaration === varDecl;\n const isTopLevelDeclaration =\n wrapper === null || wrapper?.type === 'Program';\n const isReExported =\n isTopLevelDeclaration && reExportedLocalNames.has(ancestor.id.name);\n\n if (!isDirectExport && !isReExported) {\n return null;\n }\n\n return {\n start: ancestor.init.start,\n end: ancestor.init.end,\n value: 'undefined',\n };\n }\n\n return null;\n};\n\nconst findPromiseCallbackOwner = (ancestors: Node[]): Node | null => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (\n ancestor.type === 'NewExpression' &&\n ancestor.callee.type === 'Identifier' &&\n ancestor.callee.name === 'Promise'\n ) {\n return ancestor;\n }\n\n if (\n ancestor.type === 'CallExpression' &&\n ancestor.callee.type === 'MemberExpression' &&\n promiseCallbackMethods.has(getMemberPropertyName(ancestor.callee) ?? '')\n ) {\n return ancestor;\n }\n }\n\n return null;\n};\n\nconst containsForbiddenIdentifier = (node: Node): boolean => {\n if (node.type === 'Identifier' && alwaysForbiddenIdentifiers.has(node.name)) {\n return true;\n }\n\n return getChildren(node).some(containsForbiddenIdentifier);\n};\n\nconst collectWindowScopedNames = (program: Program): Set<string> => {\n const windowScopedNames = new Set<string>();\n\n visit(program, createScope(null, 'root'), (node, scope) => {\n if (\n node.type !== 'MemberExpression' ||\n node.object.type !== 'Identifier' ||\n node.object.name !== 'window' ||\n hasBinding(scope, 'window')\n ) {\n return;\n }\n\n const propertyName = getMemberPropertyName(node);\n if (propertyName) {\n windowScopedNames.add(propertyName);\n }\n });\n\n return windowScopedNames;\n};\n\nconst containsForbiddenReference = (\n node: Node,\n scope: Scope,\n windowScopedNames: Set<string>,\n derivedForbiddenBindings: Set<string> = new Set()\n): boolean => {\n let found = false;\n\n visit(node, scope, (child, childScope, parent, ancestors) => {\n if (\n found ||\n child.type !== 'Identifier' ||\n isTypeContext(ancestors) ||\n isInsideTypeof(ancestors) ||\n isPropertyOnlyIdentifier(child, parent) ||\n isBindingPosition(child, parent)\n ) {\n return;\n }\n\n const bindingKey = getBindingKey(childScope, child.name);\n if (\n alwaysForbiddenIdentifiers.has(child.name) ||\n (forbiddenGlobals.has(child.name) &&\n !hasBinding(childScope, child.name)) ||\n (windowScopedNames.has(child.name) &&\n !hasBinding(childScope, child.name)) ||\n (bindingKey !== null && derivedForbiddenBindings.has(bindingKey))\n ) {\n found = true;\n }\n });\n\n return found;\n};\n\nconst nameFromModuleExport = (node: Node): string | null => {\n if (node.type === 'Identifier') {\n return node.name;\n }\n\n if (node.type === 'Literal' && typeof node.value === 'string') {\n return node.value;\n }\n\n return null;\n};\n\nconst collectImportBindings = (\n code: string,\n filename: string,\n program: Program\n): ImportBinding[] => {\n const bindings = new Map<string, ImportBinding>();\n const addBinding = (binding: ImportBinding): void => {\n bindings.set(\n `${binding.local}\\0${binding.source}\\0${binding.imported}`,\n binding\n );\n };\n\n program.body.forEach((statement) => {\n if (statement.type !== 'ImportDeclaration') {\n return;\n }\n\n const source = statement.source.value;\n statement.specifiers.forEach((specifier) => {\n if (specifier.type === 'ImportDefaultSpecifier') {\n addBinding({\n imported: 'default',\n local: specifier.local.name,\n source,\n });\n return;\n }\n\n if (specifier.type === 'ImportNamespaceSpecifier') {\n addBinding({\n imported: '*',\n local: specifier.local.name,\n source,\n });\n return;\n }\n\n const imported = nameFromModuleExport(specifier.imported);\n if (!imported) {\n return;\n }\n\n addBinding({\n imported,\n local: specifier.local.name,\n source,\n });\n });\n });\n\n if (!requireCallRe.test(code)) {\n return [...bindings.values()];\n }\n\n collectOxcExportsAndImports(code, filename).imports.forEach((item) => {\n if (item.imported === 'side-effect') {\n return;\n }\n\n addBinding({\n imported: item.imported,\n local: item.local.code,\n source: item.source,\n });\n\n if (item.local.name && item.local.name !== item.local.code) {\n addBinding({\n imported: item.imported,\n local: item.local.name,\n source: item.source,\n });\n }\n });\n\n return [...bindings.values()];\n};\n\nconst getImportBinding = (\n imports: ImportBinding[],\n local: string\n): ImportBinding | undefined => imports.find((item) => item.local === local);\n\nfunction unwrapSequenceCallee(node: Expression): Expression {\n if (\n node.type === 'SequenceExpression' &&\n node.expressions.length === 2 &&\n node.expressions[0]?.type === 'Literal' &&\n node.expressions[0].value === 0\n ) {\n return node.expressions[1] as Expression;\n }\n\n return node;\n}\n\nconst getExpressionImportKey = (node: Expression): string | null => {\n const expression = unwrapSequenceCallee(node);\n\n if (expression.type === 'Identifier') {\n return expression.name;\n }\n\n if (expression.type !== 'MemberExpression') {\n return null;\n }\n\n if (expression.object.type !== 'Identifier') {\n return null;\n }\n\n const propertyName = getMemberPropertyName(expression);\n return propertyName ? `${expression.object.name}.${propertyName}` : null;\n};\n\nconst isHookOrCreateElement = (name: string): boolean =>\n name === 'createElement' || /use[A-Z]/.test(name);\n\nconst getInnermostCallee = (call: CallExpression): Expression => {\n let callee = unwrapSequenceCallee(call.callee);\n while (callee.type === 'CallExpression') {\n callee = unwrapSequenceCallee(callee.callee);\n }\n\n return callee;\n};\n\nconst getImportForExpression = (\n node: Expression,\n imports: ImportBinding[]\n): [source: string, imported: string] | undefined => {\n const expression = unwrapSequenceCallee(node);\n const directMatchKey = getExpressionImportKey(expression);\n if (directMatchKey) {\n const directMatch = getImportBinding(imports, directMatchKey);\n if (directMatch) {\n return [directMatch.source, directMatch.imported];\n }\n }\n\n if (expression.type === 'Identifier') {\n const matched = getImportBinding(imports, expression.name);\n return matched ? [matched.source, matched.imported] : undefined;\n }\n\n if (expression.type !== 'MemberExpression') {\n return undefined;\n }\n\n if (expression.object.type !== 'Identifier') {\n return undefined;\n }\n\n const propertyName = getMemberPropertyName(expression);\n if (!propertyName) {\n return undefined;\n }\n\n const objectImport = getImportBinding(imports, expression.object.name);\n if (!objectImport) {\n return undefined;\n }\n\n if (\n objectImport.imported === 'default' ||\n objectImport.imported === '*' ||\n objectImport.source === 'react'\n ) {\n return [objectImport.source, propertyName];\n }\n\n return undefined;\n};\n\nconst isReactRuntimeCall = (\n call: CallExpression,\n imports: ImportBinding[]\n): boolean => {\n const callee = unwrapSequenceCallee(call.callee);\n const matched = getImportForExpression(callee, imports);\n if (!matched) {\n return false;\n }\n\n const [source, imported] = matched;\n if (jsxRuntimeSources.has(source)) {\n return true;\n }\n\n return source === 'react' && isHookOrCreateElement(imported);\n};\n\nconst isHocCall = (\n call: CallExpression,\n hocs: Record<string, string[]>,\n imports: ImportBinding[]\n): boolean => {\n const matched = getImportForExpression(getInnermostCallee(call), imports);\n return !!matched && hocs[matched[0]]?.includes(matched[1]);\n};\n\nconst isInsideHocCall = (\n ancestors: Node[],\n hocs: Record<string, string[]>,\n imports: ImportBinding[]\n): boolean =>\n ancestors.some(\n (ancestor): ancestor is CallExpression =>\n ancestor.type === 'CallExpression' && isHocCall(ancestor, hocs, imports)\n );\n\nconst getComponentTypes = (\n options?: CodeRemoverOptions\n): Record<string, string[]> => {\n const componentTypes = {\n ...(options?.componentTypes ?? { react: [defaultPlaceholder] }),\n };\n const reactTypes = componentTypes.react;\n\n if (Array.isArray(reactTypes) && reactTypes.includes(defaultPlaceholder)) {\n const idx = reactTypes.indexOf(defaultPlaceholder);\n componentTypes.react = [...reactTypes];\n componentTypes.react.splice(idx, 1, ...defaultReactComponentTypes);\n }\n\n return componentTypes;\n};\n\nconst getHocs = (options?: CodeRemoverOptions): Record<string, string[]> => {\n const hocs = {\n ...(options?.hocs ?? {}),\n };\n const reactHocs = new Set([...defaultReactHocs, ...(hocs.react ?? [])]);\n\n hocs.react = [...reactHocs];\n return hocs;\n};\n\nconst getTypeImport = (\n node: Node,\n imports: ImportBinding[]\n): [source: string, imported: string] | undefined => {\n if (node.type === 'Identifier') {\n const matched = getImportBinding(imports, node.name);\n return matched ? [matched.source, matched.imported] : undefined;\n }\n\n if (node.type !== 'TSQualifiedName') {\n return undefined;\n }\n\n if (node.left.type !== 'Identifier') {\n return undefined;\n }\n\n const matched = getImportBinding(imports, node.left.name);\n return matched ? [matched.source, node.right.name] : undefined;\n};\n\nconst isComponentTypeMatch = (\n id: Node,\n componentTypes: Record<string, string[]>,\n imports: ImportBinding[]\n): boolean => {\n if (id.type !== 'Identifier') {\n return false;\n }\n\n const annotation = id.typeAnnotation;\n if (\n !annotation ||\n annotation.type !== 'TSTypeAnnotation' ||\n annotation.typeAnnotation.type !== 'TSTypeReference'\n ) {\n return false;\n }\n\n const matched = getTypeImport(annotation.typeAnnotation.typeName, imports);\n return !!matched && componentTypes[matched[0]]?.includes(matched[1]);\n};\n\nconst getClassName = (node: Node): string | null =>\n node.type === 'ClassDeclaration' && node.id ? node.id.name : null;\n\nconst isFunctionLikeNode = (node: Node): node is OxcFunctionLikeNode =>\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression';\n\nconst isImmediatelyInvokedFunction = (\n fnNode: Node,\n ancestors: Node[],\n fnIndex: number\n): boolean => {\n // Walk past any ParenthesizedExpression / SequenceExpression wrappers that\n // sit between the function and its enclosing CallExpression. oxc-parser\n // preserves ParenthesizedExpression nodes, so `(() => {...})()` shows up\n // as CallExpression -> ParenthesizedExpression -> ArrowFunctionExpression.\n let child: Node = fnNode;\n for (let idx = fnIndex - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (\n ancestor.type === 'ParenthesizedExpression' &&\n 'expression' in ancestor &&\n ancestor.expression === child\n ) {\n child = ancestor;\n continue;\n }\n if (\n ancestor.type === 'SequenceExpression' &&\n Array.isArray(ancestor.expressions) &&\n ancestor.expressions[ancestor.expressions.length - 1] === child\n ) {\n child = ancestor;\n continue;\n }\n return ancestor.type === 'CallExpression' && ancestor.callee === child;\n }\n return false;\n};\n\n// A reference is \"deferred\" when it lives inside a function body that is\n// not immediately invoked. Module preeval reads exports without calling\n// them, so deferred references never run and must not be sanitized — that\n// would silently drop the binding (or remove the entire export) and break\n// importers that expect the function to be callable.\nconst isInDeferredFunctionScope = (ancestors: Node[]): boolean => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (!isFunctionLikeNode(ancestor)) {\n continue;\n }\n if (!isImmediatelyInvokedFunction(ancestor, ancestors, idx)) {\n return true;\n }\n }\n return false;\n};\n\nconst findFunctionReplacement = (ancestors: Node[]): Replacement | null => {\n const renderMethod = findLastAncestor(\n ancestors,\n (ancestor) =>\n ancestor.type === 'MethodDefinition' &&\n ancestor.key.type === 'Identifier' &&\n ancestor.key.name === 'render'\n );\n\n if (renderMethod) {\n const classDecl = findLastAncestor(\n ancestors,\n (ancestor) => ancestor.type === 'ClassDeclaration'\n );\n const className = classDecl ? getClassName(classDecl) : null;\n if (classDecl && className) {\n return {\n start: classDecl.start,\n end: classDecl.end,\n value: `function ${className}() { return null; }`,\n };\n }\n }\n\n const functionNode = findLastAncestor(ancestors, isFunctionLikeNode);\n\n if (!functionNode) {\n return null;\n }\n\n if (functionNode.type === 'ArrowFunctionExpression') {\n return {\n start: functionNode.start,\n end: functionNode.end,\n value: `${functionNode.async ? 'async ' : ''}() => { return null; }`,\n };\n }\n\n if (functionNode.type === 'FunctionDeclaration') {\n return {\n start: functionNode.start,\n end: functionNode.end,\n value: `${functionNode.async ? 'async ' : ''}function ${\n functionNode.id?.name ?? ''\n }() { return null; }`,\n };\n }\n\n return {\n start: functionNode.body.start,\n end: functionNode.body.end,\n value: '{ return null; }',\n };\n};\n\nconst normalizeReplacements = (replacements: Replacement[]): Replacement[] => {\n const sorted = [...replacements].sort((a, b) =>\n a.start === b.start ? b.end - a.end : a.start - b.start\n );\n const result: Replacement[] = [];\n\n sorted.forEach((replacement) => {\n const last = result[result.length - 1];\n if (\n last &&\n replacement.start >= last.start &&\n replacement.end <= last.end\n ) {\n return;\n }\n\n result.push(replacement);\n });\n\n return result;\n};\n\nexport const removeDangerousCodeWithOxc = (\n code: string,\n filename: string,\n options?: CodeRemoverOptions\n): string => {\n const replacements: Replacement[] = [];\n const derivedForbiddenBindings = new Set<string>();\n const program = parseOxc(code, filename);\n const imports = collectImportBindings(code, filename, program);\n const componentTypes = getComponentTypes(options);\n const hocs = getHocs(options);\n const hasHocs = Object.keys(hocs).length > 0;\n const windowScopedNames = windowTokenRe.test(code)\n ? collectWindowScopedNames(program)\n : new Set<string>();\n const reExportedLocalNames = collectReExportedLocalNames(program);\n\n const derivedBindingDiscovery = { found: true };\n while (derivedBindingDiscovery.found) {\n derivedBindingDiscovery.found = false;\n\n visit(program, createScope(null, 'root'), (node, scope) => {\n if (\n node.type !== 'VariableDeclarator' ||\n node.id.type !== 'Identifier' ||\n !node.init\n ) {\n return;\n }\n\n const bindingKey = getBindingKey(scope, node.id.name);\n if (!bindingKey || derivedForbiddenBindings.has(bindingKey)) {\n return;\n }\n\n if (\n containsForbiddenIdentifier(node.init) ||\n containsForbiddenReference(\n node.init,\n scope,\n windowScopedNames,\n derivedForbiddenBindings\n )\n ) {\n derivedForbiddenBindings.add(bindingKey);\n derivedBindingDiscovery.found = true;\n }\n });\n }\n\n visit(\n program,\n createScope(null, 'root'),\n (node, scope, parent, ancestors) => {\n if (node.type === 'JSXElement' || node.type === 'JSXFragment') {\n replacements.push(\n findFunctionReplacement(ancestors) ?? {\n start: node.start,\n end: node.end,\n value: 'null',\n }\n );\n return;\n }\n\n if (node.type === 'CallExpression') {\n if (isReactRuntimeCall(node, imports)) {\n const replacement = findFunctionReplacement(ancestors);\n if (replacement) {\n replacements.push(replacement);\n }\n\n return;\n }\n\n if (hasHocs && isHocCall(node, hocs, imports)) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: '() => null',\n });\n return;\n }\n }\n\n if (\n node.type === 'VariableDeclarator' &&\n node.id.type === 'Identifier' &&\n node.init &&\n isComponentTypeMatch(node.id, componentTypes, imports)\n ) {\n replacements.push({\n start: node.init.start,\n end: node.init.end,\n value: '() => null',\n });\n return;\n }\n\n if (\n node.type === 'UnaryExpression' &&\n node.operator === 'typeof' &&\n node.argument.type === 'Identifier' &&\n ssrCheckFields.has(node.argument.name) &&\n !hasBinding(scope, node.argument.name)\n ) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: '\"undefined\"',\n });\n return;\n }\n\n if (node.type === 'MetaProperty') {\n const owner = findRemovableOwner(node, ancestors);\n replacements.push({ start: owner.start, end: owner.end, value: '' });\n return;\n }\n\n if (\n node.type !== 'Identifier' ||\n isTypeContext(ancestors) ||\n isInsideTypeof(ancestors) ||\n isInsideImportDeclaration(ancestors)\n ) {\n return;\n }\n\n if (isPropertyOnlyIdentifier(node, parent)) {\n return;\n }\n\n const isAlwaysForbidden = alwaysForbiddenIdentifiers.has(node.name);\n const bindingKey = getBindingKey(scope, node.name);\n const isDerivedForbidden =\n bindingKey !== null && derivedForbiddenBindings.has(bindingKey);\n const isWindowScoped =\n windowScopedNames.has(node.name) && !hasBinding(scope, node.name);\n const isForbiddenGlobal =\n forbiddenGlobals.has(node.name) && !hasBinding(scope, node.name);\n\n if (\n !isAlwaysForbidden &&\n !isDerivedForbidden &&\n !isWindowScoped &&\n !isForbiddenGlobal\n ) {\n return;\n }\n\n if (!isAlwaysForbidden && isInDeferredFunctionScope(ancestors)) {\n return;\n }\n\n if (hasHocs && isInsideHocCall(ancestors, hocs, imports)) {\n return;\n }\n\n if (isBindingPosition(node, parent) && !isAlwaysForbidden) {\n return;\n }\n\n if (\n parent?.type === 'ExportDefaultDeclaration' &&\n parent.declaration === node\n ) {\n return;\n }\n\n if (\n generatedProcessorHelperNameRe.test(node.name) &&\n hasBinding(scope, node.name)\n ) {\n return;\n }\n\n const generatedHelperDeclarator = findLastAncestor(\n ancestors,\n (ancestor) =>\n ancestor.type === 'VariableDeclarator' &&\n ancestor.id.type === 'Identifier' &&\n generatedProcessorHelperNameRe.test(ancestor.id.name)\n );\n if (generatedHelperDeclarator) {\n return;\n }\n\n if (\n parent?.type === 'Property' &&\n parent.value === node &&\n hasBinding(scope, node.name)\n ) {\n return;\n }\n\n if (parent?.type === 'Property' && parent.value === node) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: parent.shorthand ? `${node.name}: undefined` : 'undefined',\n });\n return;\n }\n\n const grandparent = ancestors[ancestors.length - 2] ?? null;\n if (\n parent?.type === 'MemberExpression' &&\n parent.object === node &&\n grandparent?.type === 'SpreadElement' &&\n grandparent.argument === parent\n ) {\n replacements.push({\n start: grandparent.start,\n end: grandparent.end,\n value: '...{}',\n });\n return;\n }\n\n const exportProtection = findExportedBindingProtection(\n node,\n ancestors,\n reExportedLocalNames\n );\n if (exportProtection) {\n replacements.push(exportProtection);\n return;\n }\n\n const promiseOwner = findPromiseCallbackOwner(ancestors);\n const owner = promiseOwner\n ? findRemovableOwner(promiseOwner, ancestors)\n : findRemovableOwner(node, ancestors);\n replacements.push({ start: owner.start, end: owner.end, value: '' });\n }\n );\n\n return applyReplacements(code, normalizeReplacements(replacements));\n};\n"],"file":"oxcPreevalTransforms.js"}
1
+ {"mappings":"AAYA,SAAS,mCAAmC;AAC5C,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AAiCtC,MAAM,iBAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,mBAAmB,IAAI,IAAI;CAC/B,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,6BAA6B,IAAI,IAAI,CAAC,gBAAgB,eAAe,CAAC;AAC5E,MAAM,yBAAyB,IAAI,IAAI;CAAC;CAAQ;CAAS;CAAU,CAAC;AACpE,MAAM,oBAAoB,IAAI,IAAI,CAChC,qBACA,wBACD,CAAC;AACF,MAAM,qBAAqB;AAC3B,MAAM,6BAA6B;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AACD,MAAM,mBAAmB,CAAC,cAAc,OAAO;AAC/C,MAAM,iCAAiC;AACvC,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;AACtB,MAAM,sBAAsB,IAAI,IAAI;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AACF,MAAM,kBAAkB;AAExB,MAAM,eAAe,QAAsB,SAAwB;CACjE,UAAU,IAAI,KAAK;CACnB;CACA,OAAO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Y,aAAa,QACzB;AACA,gBAAa,KAAK;IAChB,OAAO,YAAY;IACnB,KAAK,YAAY;IACjB,OAAO;IACR,CAAC;AACF;;EAGF,MAAM,mBAAmB,8BACvB,MACA,WACA,qBACD;AACD,MAAI,kBAAkB;AACpB,gBAAa,KAAK,iBAAiB;AACnC;;EAGF,MAAM,eAAe,yBAAyB,UAAU;EACxD,MAAM,QAAQ,eACV,mBAAmB,cAAc,UAAU,GAC3C,mBAAmB,MAAM,UAAU;AACvC,eAAa,KAAK;GAAE,OAAO,MAAM;GAAO,KAAK,MAAM;GAAK,OAAO;GAAI,CAAC;GAEvE;AAED,QAAO,kBAAkB,MAAM,sBAAsB,aAAa,CAAC","names":[],"sources":["../../src/utils/oxcPreevalTransforms.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue */\n\nimport type {\n CallExpression,\n Expression,\n ImportExpression,\n Node,\n Program,\n} from 'oxc-parser';\n\nimport type { CodeRemoverOptions } from '@wyw-in-js/shared';\n\nimport { collectOxcExportsAndImports } from './collectOxcExportsAndImports';\nimport { EventEmitter } from './EventEmitter';\nimport { getOxcNodeChildren } from './oxc/ast';\nimport { parseOxcProgramCached } from './parseOxc';\n\ntype AnyNode = Node & Record<string, unknown>;\n\ntype Replacement = {\n end: number;\n start: number;\n value: string;\n};\n\ntype Scope = {\n bindings: Map<string, Expression | null>;\n key: string;\n names: Set<string>;\n parent: Scope | null;\n};\n\ntype ImportBinding = {\n imported: string | 'default' | '*';\n local: string;\n source: string;\n};\n\ntype OxcFunctionLikeNode = Node & {\n async: boolean;\n body: Node;\n id?: { name: string } | null;\n type:\n | 'ArrowFunctionExpression'\n | 'FunctionDeclaration'\n | 'FunctionExpression';\n};\n\nconst ssrCheckFields = new Set([\n 'document',\n 'location',\n 'navigator',\n 'sessionStorage',\n 'localStorage',\n 'window',\n]);\n\nconst forbiddenGlobals = new Set([\n ...ssrCheckFields,\n '$RefreshReg$',\n '$RefreshSig$',\n 'XMLHttpRequest',\n 'clearImmediate',\n 'clearInterval',\n 'clearTimeout',\n 'fetch',\n 'navigator',\n 'setImmediate',\n 'setInterval',\n 'setTimeout',\n]);\n\nconst alwaysForbiddenIdentifiers = new Set(['$RefreshReg$', '$RefreshSig$']);\nconst promiseCallbackMethods = new Set(['then', 'catch', 'finally']);\nconst jsxRuntimeSources = new Set([\n 'react/jsx-runtime',\n 'react/jsx-dev-runtime',\n]);\nconst defaultPlaceholder = '...';\nconst defaultReactComponentTypes = [\n 'ExoticComponent',\n 'FC',\n 'ForwardRefExoticComponent',\n 'FunctionComponent',\n 'LazyExoticComponent',\n 'MemoExoticComponent',\n 'NamedExoticComponent',\n];\nconst defaultReactHocs = ['forwardRef', 'memo'];\nconst generatedProcessorHelperNameRe = /^_exp\\d*$/;\nconst requireCallRe = /\\brequire\\s*\\(/;\nconst windowTokenRe = /\\bwindow\\b/;\nconst removableOwnerTypes = new Set([\n 'DoWhileStatement',\n 'ExpressionStatement',\n 'ForInStatement',\n 'ForOfStatement',\n 'ForStatement',\n 'FunctionDeclaration',\n 'IfStatement',\n 'PropertyDefinition',\n 'ReturnStatement',\n 'VariableDeclaration',\n 'WhileStatement',\n]);\nconst importMetaEnvRe = /\\bimport\\s*\\.\\s*meta\\s*\\.\\s*env\\b/;\n\nconst createScope = (parent: Scope | null, key: string): Scope => ({\n bindings: new Map(),\n key,\n names: new Set(),\n parent,\n});\n\nconst createsScope = (node: Node): boolean =>\n node.type === 'Program' ||\n node.type === 'BlockStatement' ||\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression';\n\nconst hasBinding = (scope: Scope, name: string): boolean => {\n let current: Scope | null = scope;\n while (current) {\n if (current.names.has(name)) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n};\n\nconst getBindingKey = (scope: Scope, name: string): string | null => {\n let current: Scope | null = scope;\n while (current) {\n if (current.names.has(name)) {\n return `${current.key}\\0${name}`;\n }\n\n current = current.parent;\n }\n\n return null;\n};\n\nconst getStaticBinding = (\n scope: Scope,\n name: string\n): Expression | null | undefined => {\n let current: Scope | null = scope;\n while (current) {\n if (current.bindings.has(name)) {\n return current.bindings.get(name);\n }\n\n current = current.parent;\n }\n\n return undefined;\n};\n\nconst isFileLikeRequireSpecifier = (value: string): boolean =>\n value.startsWith('.') || value.startsWith('/') || value.startsWith('file:');\n\nconst isNode = (value: unknown): value is Node =>\n !!value &&\n typeof value === 'object' &&\n 'type' in value &&\n typeof (value as { type?: unknown }).type === 'string';\n\n// Reuses the per-node.type visitor-key cache in utils/oxc/ast.ts. This file's\n// getChildren shape historically diverged from the canonical one (a smaller\n// metadata-key skip set), but the produced children list is identical in\n// practice because oxc-parser nodes don't carry the extra metadata fields.\nconst getChildren = getOxcNodeChildren;\n\nconst parseOxc = (code: string, filename: string): Program => {\n return parseOxcProgramCached(filename, code, 'unambiguous');\n};\n\nconst unwrapExpression = (node: Expression): Expression => {\n if (\n node.type === 'TSAsExpression' ||\n node.type === 'TSSatisfiesExpression' ||\n node.type === 'TSNonNullExpression' ||\n node.type === 'TSTypeAssertion' ||\n node.type === 'ParenthesizedExpression'\n ) {\n return unwrapExpression(node.expression);\n }\n\n return node;\n};\n\nconst getMemberPropertyName = (node: Node): string | null => {\n if (node.type !== 'MemberExpression') {\n return null;\n }\n\n if (node.computed) {\n return node.property.type === 'Literal' &&\n typeof node.property.value === 'string'\n ? node.property.value\n : null;\n }\n\n return node.property.type === 'Identifier' ? node.property.name : null;\n};\n\nconst isStringLikeExpression = (node: Expression): boolean => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal' && typeof expression.value === 'string') {\n return true;\n }\n\n if (expression.type === 'TemplateLiteral') {\n return true;\n }\n\n if (expression.type === 'BinaryExpression' && expression.operator === '+') {\n return (\n isStringLikeExpression(expression.left) ||\n isStringLikeExpression(expression.right)\n );\n }\n\n if (\n expression.type === 'CallExpression' &&\n expression.callee.type === 'MemberExpression' &&\n getMemberPropertyName(expression.callee) === 'concat'\n ) {\n return isStringLikeExpression(expression.callee.object);\n }\n\n return false;\n};\n\nconst templateLiteralToConcat = (code: string, node: Expression): string => {\n if (node.type !== 'TemplateLiteral' || node.expressions.length === 0) {\n return code.slice(node.start, node.end);\n }\n\n const parts: string[] = [];\n node.quasis.forEach((quasi, index) => {\n const cooked = quasi.value.cooked ?? quasi.value.raw;\n if (cooked !== '') {\n parts.push(JSON.stringify(cooked));\n }\n\n const expression = node.expressions[index];\n if (expression) {\n parts.push(code.slice(expression.start, expression.end));\n }\n });\n\n return parts.length > 0 ? parts.join(' + ') : '\"\"';\n};\n\nconst dynamicImportArgumentCode = (code: string, node: Expression): string => {\n if (node.type === 'TemplateLiteral') {\n return templateLiteralToConcat(code, node);\n }\n\n return code.slice(node.start, node.end);\n};\n\nconst evaluateStaticValue = (\n node: Expression,\n scope: Scope,\n seen = new Set<string>()\n): unknown | undefined => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal') {\n return expression.value;\n }\n\n if (expression.type === 'TemplateLiteral') {\n let result = '';\n\n for (let idx = 0; idx < expression.quasis.length; idx += 1) {\n result += expression.quasis[idx]?.value.cooked ?? '';\n\n const nextExpression = expression.expressions[idx];\n if (!nextExpression) {\n continue;\n }\n\n const value = evaluateStaticValue(nextExpression, scope, seen);\n if (\n value === undefined ||\n (typeof value !== 'string' && typeof value !== 'number')\n ) {\n return undefined;\n }\n\n result += String(value);\n }\n\n return result;\n }\n\n if (expression.type === 'Identifier') {\n if (seen.has(expression.name)) {\n return undefined;\n }\n\n const binding = getStaticBinding(scope, expression.name);\n if (!binding) {\n return undefined;\n }\n\n return evaluateStaticValue(\n binding,\n scope,\n new Set([...seen, expression.name])\n );\n }\n\n if (expression.type === 'BinaryExpression' && expression.operator === '+') {\n const left = evaluateStaticValue(expression.left, scope, seen);\n const right = evaluateStaticValue(expression.right, scope, seen);\n\n if (left === undefined || right === undefined) {\n return undefined;\n }\n\n if (typeof left === 'number' && typeof right === 'number') {\n return left + right;\n }\n\n if (\n (typeof left === 'string' || typeof left === 'number') &&\n (typeof right === 'string' || typeof right === 'number')\n ) {\n return `${left}${right}`;\n }\n }\n\n if (\n expression.type === 'CallExpression' &&\n expression.callee.type === 'MemberExpression'\n ) {\n const objectValue = evaluateStaticValue(\n expression.callee.object,\n scope,\n seen\n );\n const propertyName = getMemberPropertyName(expression.callee);\n if (!propertyName) {\n return undefined;\n }\n\n if (typeof objectValue === 'string') {\n if (propertyName === 'toLowerCase' && expression.arguments.length === 0) {\n return objectValue.toLowerCase();\n }\n\n if (propertyName === 'toUpperCase' && expression.arguments.length === 0) {\n return objectValue.toUpperCase();\n }\n\n if (propertyName === 'trim' && expression.arguments.length === 0) {\n return objectValue.trim();\n }\n\n if (propertyName === 'concat') {\n const args = expression.arguments.map((argument) =>\n argument.type === 'SpreadElement'\n ? undefined\n : evaluateStaticValue(argument, scope, seen)\n );\n if (\n args.some((value) => value === undefined) ||\n args.some(\n (value) => typeof value !== 'string' && typeof value !== 'number'\n )\n ) {\n return undefined;\n }\n\n return objectValue.concat(...args.map((value) => String(value)));\n }\n }\n }\n\n return undefined;\n};\n\nconst isLiteralRequireArg = (node: Expression): boolean => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal' && typeof expression.value === 'string') {\n return true;\n }\n\n if (\n expression.type === 'TemplateLiteral' &&\n expression.expressions.length === 0\n ) {\n return true;\n }\n\n return false;\n};\n\nconst applyReplacements = (\n code: string,\n replacements: Replacement[]\n): string => {\n let result = code;\n replacements\n .sort((a, b) => b.start - a.start)\n .forEach((replacement) => {\n result =\n result.slice(0, replacement.start) +\n replacement.value +\n result.slice(replacement.end);\n });\n\n return result;\n};\n\nconst isIdentifierNamed = (value: unknown, name: string): boolean =>\n isNode(value) && value.type === 'Identifier' && value.name === name;\n\nconst isImportMeta = (node: unknown): boolean => {\n if (!isNode(node) || node.type !== 'MetaProperty') {\n return false;\n }\n\n const metaProperty = node as AnyNode;\n return (\n isIdentifierNamed(metaProperty.meta, 'import') &&\n isIdentifierNamed(metaProperty.property, 'meta')\n );\n};\n\nconst isImportMetaEnv = (node: Node): boolean => {\n if (node.type !== 'MemberExpression') {\n return false;\n }\n\n if (node.computed || !isIdentifierNamed(node.property, 'env')) {\n return false;\n }\n\n return isImportMeta(node.object);\n};\n\nconst collectBindingNames = (node: Node): string[] => {\n if (node.type === 'Identifier') {\n return [node.name];\n }\n\n if (node.type === 'RestElement') {\n return collectBindingNames(node.argument);\n }\n\n if (node.type === 'AssignmentPattern') {\n return collectBindingNames(node.left);\n }\n\n if (node.type === 'ObjectPattern') {\n return node.properties.flatMap((property) =>\n property.type === 'RestElement'\n ? collectBindingNames(property.argument)\n : collectBindingNames(property.value)\n );\n }\n\n if (node.type === 'ArrayPattern') {\n return node.elements.flatMap((element) =>\n element ? collectBindingNames(element) : []\n );\n }\n\n if (node.type === 'TSParameterProperty') {\n return collectBindingNames(node.parameter);\n }\n\n return [];\n};\n\nconst predeclareScopeNames = (node: Node, scope: Scope): void => {\n if (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n if (node.type !== 'ArrowFunctionExpression' && node.id) {\n scope.names.add(node.id.name);\n }\n\n node.params.forEach((param) => {\n collectBindingNames(param).forEach((name) => {\n scope.names.add(name);\n });\n });\n }\n\n const visitScopeDescendants = (child: Node): void => {\n switch (child.type) {\n case 'VariableDeclarator': {\n const names = collectBindingNames(child.id);\n for (let i = 0; i < names.length; i += 1) {\n scope.names.add(names[i]);\n }\n break;\n }\n case 'FunctionDeclaration':\n case 'ClassDeclaration':\n if (child.id) {\n scope.names.add(child.id.name);\n }\n break;\n case 'ImportDefaultSpecifier':\n case 'ImportNamespaceSpecifier':\n case 'ImportSpecifier':\n scope.names.add(child.local.name);\n break;\n default:\n break;\n }\n\n if (createsScope(child)) {\n return;\n }\n\n const children = getChildren(child);\n for (let i = 0; i < children.length; i += 1) {\n visitScopeDescendants(children[i]);\n }\n };\n\n const rootChildren = getChildren(node);\n for (let i = 0; i < rootChildren.length; i += 1) {\n visitScopeDescendants(rootChildren[i]);\n }\n};\n\nconst declareBindings = (node: Node, scope: Scope): void => {\n // Called for every visited AST node, so the dispatch is hot. A switch lets\n // V8 generate a jump table on node.type; the previous chained `if`s walked\n // each branch's string-compare for every non-matching node.\n switch (node.type) {\n case 'VariableDeclarator': {\n const names = collectBindingNames(node.id);\n for (let i = 0; i < names.length; i += 1) {\n const name = names[i];\n scope.names.add(name);\n scope.bindings.set(name, null);\n }\n if (node.id.type === 'Identifier' && node.init) {\n scope.bindings.set(node.id.name, node.init);\n }\n return;\n }\n case 'ClassDeclaration': {\n if (node.id) {\n scope.names.add(node.id.name);\n scope.bindings.set(node.id.name, null);\n }\n return;\n }\n case 'ImportDefaultSpecifier':\n case 'ImportNamespaceSpecifier':\n case 'ImportSpecifier': {\n scope.names.add(node.local.name);\n scope.bindings.set(node.local.name, null);\n return;\n }\n case 'FunctionDeclaration': {\n if (node.id) {\n scope.names.add(node.id.name);\n scope.bindings.set(node.id.name, null);\n }\n // Fall through to declare params.\n }\n // eslint-disable-next-line no-fallthrough\n case 'FunctionExpression':\n case 'ArrowFunctionExpression': {\n const { params } = node;\n for (let i = 0; i < params.length; i += 1) {\n const names = collectBindingNames(params[i]);\n for (let j = 0; j < names.length; j += 1) {\n const name = names[j];\n scope.names.add(name);\n scope.bindings.set(name, null);\n }\n }\n break;\n }\n default:\n break;\n }\n};\n\nconst visit = (\n node: Node,\n scope: Scope,\n enter: (\n node: Node,\n scope: Scope,\n parent: Node | null,\n ancestors: Node[]\n ) => void,\n parent: Node | null = null,\n ancestors: Node[] = []\n): void => {\n let currentScope = scope;\n if (createsScope(node)) {\n currentScope = createScope(scope, `${node.type}:${node.start}:${node.end}`);\n predeclareScopeNames(node, currentScope);\n }\n\n declareBindings(node, currentScope);\n enter(node, currentScope, parent, ancestors);\n\n // Push onto a shared ancestors stack instead of allocating `[...ancestors,\n // node]` per child step (O(n × depth) extra allocation on deep ASTs).\n // Every consumer of `ancestors` in this file reads it synchronously inside\n // the enter callback; future callers that need to retain the reference\n // must .slice() it themselves.\n ancestors.push(node);\n const children = getChildren(node);\n for (let i = 0; i < children.length; i += 1) {\n visit(children[i], currentScope, enter, node, ancestors);\n }\n ancestors.pop();\n};\n\nexport const replaceImportMetaEnvWithOxc = (\n code: string,\n filename: string\n): string => {\n if (!importMetaEnvRe.test(code)) {\n return code;\n }\n\n const replacements: Replacement[] = [];\n\n visit(parseOxc(code, filename), createScope(null, 'root'), (node) => {\n if (!isImportMetaEnv(node)) {\n return;\n }\n\n replacements.push({\n end: node.end,\n start: node.start,\n value: '__wyw_import_meta_env',\n });\n });\n\n return applyReplacements(code, replacements);\n};\n\ntype CombinedSyntaxRewriteOptions = {\n addRequireFallback: boolean;\n eventEmitter?: EventEmitter;\n rewriteDynamicImports: boolean;\n};\n\ntype RequireFallbackCandidate = {\n call: CallExpression;\n scope: Scope;\n};\n\nfunction collectDynamicImportAndRequireFallbackReplacements(\n code: string,\n filename: string,\n options: CombinedSyntaxRewriteOptions\n): Replacement[] {\n const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;\n const dynamicImportCandidates: ImportExpression[] = [];\n const requireFallbackCandidates: RequireFallbackCandidate[] = [];\n\n eventEmitter.perf(\n 'transform:preeval:dynamicImportRequireFallback:scan',\n () => {\n visit(\n parseOxc(code, filename),\n createScope(null, 'root'),\n (node, scope) => {\n if (\n options.rewriteDynamicImports &&\n node.type === 'ImportExpression'\n ) {\n dynamicImportCandidates.push(node as ImportExpression);\n }\n\n if (!options.addRequireFallback || node.type !== 'CallExpression') {\n return;\n }\n\n const call = node as CallExpression;\n if (\n call.callee.type !== 'Identifier' ||\n call.callee.name !== 'require' ||\n hasBinding(scope, 'require') ||\n call.arguments.length !== 1\n ) {\n return;\n }\n\n const [firstArg] = call.arguments;\n if (\n !firstArg ||\n firstArg.type === 'SpreadElement' ||\n isLiteralRequireArg(firstArg)\n ) {\n return;\n }\n\n requireFallbackCandidates.push({\n call,\n scope,\n });\n }\n );\n }\n );\n\n const replacements: Replacement[] = [];\n\n eventEmitter.perf('transform:preeval:dynamicImport', () => {\n dynamicImportCandidates.forEach((importExpression) => {\n const argument = importExpression.source;\n const nextArgument = isStringLikeExpression(argument)\n ? unwrapExpression(argument)\n : argument;\n\n replacements.push({\n end: importExpression.end,\n start: importExpression.start,\n value: `__wyw_dynamic_import(${dynamicImportArgumentCode(\n code,\n nextArgument\n )})`,\n });\n });\n });\n\n eventEmitter.perf('transform:preeval:requireFallback', () => {\n requireFallbackCandidates.forEach(({ call, scope }) => {\n const [firstArg] = call.arguments;\n if (!firstArg || firstArg.type === 'SpreadElement') {\n return;\n }\n\n const staticValue = evaluateStaticValue(firstArg, scope);\n if (\n typeof staticValue === 'string' &&\n isFileLikeRequireSpecifier(staticValue)\n ) {\n replacements.push({\n end: firstArg.end,\n start: firstArg.start,\n value: JSON.stringify(staticValue),\n });\n return;\n }\n\n replacements.push({\n end: firstArg.end,\n start: firstArg.end,\n value: ', true',\n });\n });\n });\n\n return replacements;\n}\n\nexport const rewriteDynamicImportsWithOxc = (\n code: string,\n filename: string\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n {\n addRequireFallback: false,\n rewriteDynamicImports: true,\n }\n );\n\n return applyReplacements(code, replacements);\n};\n\nexport const addRequireFallbackWithOxc = (\n code: string,\n filename: string\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n {\n addRequireFallback: true,\n rewriteDynamicImports: false,\n }\n );\n\n return applyReplacements(code, replacements);\n};\n\nexport const rewriteDynamicImportsAndAddRequireFallbackWithOxc = (\n code: string,\n filename: string,\n options: CombinedSyntaxRewriteOptions\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n options\n );\n\n return applyReplacements(code, replacements);\n};\n\nconst isBindingPosition = (node: Node, parent: Node | null): boolean => {\n if (!parent) {\n return false;\n }\n\n if (parent.type === 'VariableDeclarator' && parent.id === node) {\n return true;\n }\n\n if (\n (parent.type === 'FunctionDeclaration' ||\n parent.type === 'FunctionExpression' ||\n parent.type === 'ClassDeclaration' ||\n parent.type === 'ClassExpression') &&\n parent.id === node\n ) {\n return true;\n }\n\n if (\n parent.type === 'ImportSpecifier' &&\n (parent.local === node || parent.imported === node)\n ) {\n return true;\n }\n\n if (\n (parent.type === 'ImportDefaultSpecifier' ||\n parent.type === 'ImportNamespaceSpecifier') &&\n parent.local === node\n ) {\n return true;\n }\n\n if (\n parent.type === 'ExportSpecifier' &&\n (parent.local === node || parent.exported === node)\n ) {\n return true;\n }\n\n return false;\n};\n\nconst isPropertyOnlyIdentifier = (node: Node, parent: Node | null): boolean => {\n if (!parent) {\n return false;\n }\n\n if (\n parent.type === 'MemberExpression' &&\n !parent.computed &&\n parent.property === node\n ) {\n return true;\n }\n\n if (\n (parent.type === 'Property' ||\n parent.type === 'MethodDefinition' ||\n parent.type === 'PropertyDefinition') &&\n !parent.computed &&\n parent.key === node\n ) {\n return true;\n }\n\n return false;\n};\n\nconst isTypeContext = (ancestors: Node[]): boolean =>\n ancestors.some(\n (ancestor) =>\n ancestor.type.startsWith('TS') || ancestor.type.startsWith('JSDoc')\n );\n\nconst isInsideTypeof = (ancestors: Node[]): boolean =>\n ancestors.some(\n (ancestor) =>\n ancestor.type === 'UnaryExpression' && ancestor.operator === 'typeof'\n );\n\nconst isInsideImportDeclaration = (ancestors: Node[]): boolean =>\n ancestors.some((ancestor) => ancestor.type === 'ImportDeclaration');\n\nfunction findLastAncestor<T extends Node>(\n ancestors: Node[],\n predicate: (ancestor: Node) => ancestor is T\n): T | null;\nfunction findLastAncestor(\n ancestors: Node[],\n predicate: (ancestor: Node) => boolean\n): Node | null;\nfunction findLastAncestor(\n ancestors: Node[],\n predicate: (ancestor: Node) => boolean\n): Node | null {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (predicate(ancestor)) {\n return ancestor;\n }\n }\n\n return null;\n}\n\nconst findRemovableOwner = (node: Node, ancestors: Node[]): Node => {\n let owner: Node = node;\n let ownerAncestorIndex = -1;\n\n if (!removableOwnerTypes.has(node.type)) {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (removableOwnerTypes.has(ancestor.type)) {\n owner = ancestor;\n ownerAncestorIndex = idx;\n break;\n }\n }\n }\n\n const parent =\n ownerAncestorIndex > 0 ? ancestors[ownerAncestorIndex - 1] : null;\n if (\n parent?.type === 'ExportNamedDeclaration' &&\n 'declaration' in parent &&\n parent.declaration === owner\n ) {\n return parent;\n }\n\n return owner;\n};\n\ntype ExportedBindingProtection = {\n start: number;\n end: number;\n value: string;\n};\n\nconst collectReExportedLocalNames = (program: Program): Set<string> => {\n const names = new Set<string>();\n for (const stmt of program.body) {\n if (\n stmt.type !== 'ExportNamedDeclaration' ||\n stmt.declaration ||\n stmt.source\n ) {\n continue;\n }\n for (const spec of stmt.specifiers) {\n if (spec.type === 'ExportSpecifier' && spec.local.type === 'Identifier') {\n names.add(spec.local.name);\n }\n }\n }\n return names;\n};\n\n// When an offending identifier sits inside the value of a top-level export,\n// removing the surrounding declaration would strip the export binding too.\n// ESM linker then fails on consumers' `import { name } from '...'` because the\n// named export no longer exists. To keep the binding alive, replace just the\n// value (declarator init or default-export expression) with `undefined`.\nconst findExportedBindingProtection = (\n node: Node,\n ancestors: Node[],\n reExportedLocalNames: Set<string>\n): ExportedBindingProtection | null => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n\n if (ancestor.type === 'ExportDefaultDeclaration') {\n const decl = ancestor.declaration;\n if (decl && decl !== node && 'start' in decl && 'end' in decl) {\n return { start: decl.start, end: decl.end, value: 'undefined' };\n }\n return null;\n }\n\n if (ancestor.type !== 'VariableDeclarator') {\n continue;\n }\n\n if (\n ancestor.id.type !== 'Identifier' ||\n !ancestor.init ||\n ancestor.init === node\n ) {\n return null;\n }\n\n const varDecl = ancestors[idx - 1];\n const wrapper = ancestors[idx - 2] ?? null;\n\n if (varDecl?.type !== 'VariableDeclaration') {\n return null;\n }\n\n const isDirectExport =\n wrapper?.type === 'ExportNamedDeclaration' &&\n wrapper.declaration === varDecl;\n const isTopLevelDeclaration =\n wrapper === null || wrapper?.type === 'Program';\n const isReExported =\n isTopLevelDeclaration && reExportedLocalNames.has(ancestor.id.name);\n\n if (!isDirectExport && !isReExported) {\n return null;\n }\n\n return {\n start: ancestor.init.start,\n end: ancestor.init.end,\n value: 'undefined',\n };\n }\n\n return null;\n};\n\nconst findPromiseCallbackOwner = (ancestors: Node[]): Node | null => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (\n ancestor.type === 'NewExpression' &&\n ancestor.callee.type === 'Identifier' &&\n ancestor.callee.name === 'Promise'\n ) {\n return ancestor;\n }\n\n if (\n ancestor.type === 'CallExpression' &&\n ancestor.callee.type === 'MemberExpression' &&\n promiseCallbackMethods.has(getMemberPropertyName(ancestor.callee) ?? '')\n ) {\n return ancestor;\n }\n }\n\n return null;\n};\n\nconst containsForbiddenIdentifier = (node: Node): boolean => {\n if (node.type === 'Identifier' && alwaysForbiddenIdentifiers.has(node.name)) {\n return true;\n }\n\n return getChildren(node).some(containsForbiddenIdentifier);\n};\n\nconst collectWindowScopedNames = (program: Program): Set<string> => {\n const windowScopedNames = new Set<string>();\n\n visit(program, createScope(null, 'root'), (node, scope) => {\n if (\n node.type !== 'MemberExpression' ||\n node.object.type !== 'Identifier' ||\n node.object.name !== 'window' ||\n hasBinding(scope, 'window')\n ) {\n return;\n }\n\n const propertyName = getMemberPropertyName(node);\n if (propertyName) {\n windowScopedNames.add(propertyName);\n }\n });\n\n return windowScopedNames;\n};\n\nconst containsForbiddenReference = (\n node: Node,\n scope: Scope,\n windowScopedNames: Set<string>,\n derivedForbiddenBindings: Set<string> = new Set()\n): boolean => {\n let found = false;\n\n visit(node, scope, (child, childScope, parent, ancestors) => {\n if (\n found ||\n child.type !== 'Identifier' ||\n isTypeContext(ancestors) ||\n isInsideTypeof(ancestors) ||\n isPropertyOnlyIdentifier(child, parent) ||\n isBindingPosition(child, parent)\n ) {\n return;\n }\n\n const bindingKey = getBindingKey(childScope, child.name);\n if (\n alwaysForbiddenIdentifiers.has(child.name) ||\n (forbiddenGlobals.has(child.name) &&\n !hasBinding(childScope, child.name)) ||\n (windowScopedNames.has(child.name) &&\n !hasBinding(childScope, child.name)) ||\n (bindingKey !== null && derivedForbiddenBindings.has(bindingKey))\n ) {\n found = true;\n }\n });\n\n return found;\n};\n\nconst nameFromModuleExport = (node: Node): string | null => {\n if (node.type === 'Identifier') {\n return node.name;\n }\n\n if (node.type === 'Literal' && typeof node.value === 'string') {\n return node.value;\n }\n\n return null;\n};\n\nconst collectImportBindings = (\n code: string,\n filename: string,\n program: Program\n): ImportBinding[] => {\n const bindings = new Map<string, ImportBinding>();\n const addBinding = (binding: ImportBinding): void => {\n bindings.set(\n `${binding.local}\\0${binding.source}\\0${binding.imported}`,\n binding\n );\n };\n\n program.body.forEach((statement) => {\n if (statement.type !== 'ImportDeclaration') {\n return;\n }\n\n const source = statement.source.value;\n statement.specifiers.forEach((specifier) => {\n if (specifier.type === 'ImportDefaultSpecifier') {\n addBinding({\n imported: 'default',\n local: specifier.local.name,\n source,\n });\n return;\n }\n\n if (specifier.type === 'ImportNamespaceSpecifier') {\n addBinding({\n imported: '*',\n local: specifier.local.name,\n source,\n });\n return;\n }\n\n const imported = nameFromModuleExport(specifier.imported);\n if (!imported) {\n return;\n }\n\n addBinding({\n imported,\n local: specifier.local.name,\n source,\n });\n });\n });\n\n if (!requireCallRe.test(code)) {\n return [...bindings.values()];\n }\n\n collectOxcExportsAndImports(code, filename).imports.forEach((item) => {\n if (item.imported === 'side-effect') {\n return;\n }\n\n addBinding({\n imported: item.imported,\n local: item.local.code,\n source: item.source,\n });\n\n if (item.local.name && item.local.name !== item.local.code) {\n addBinding({\n imported: item.imported,\n local: item.local.name,\n source: item.source,\n });\n }\n });\n\n return [...bindings.values()];\n};\n\nconst getImportBinding = (\n imports: ImportBinding[],\n local: string\n): ImportBinding | undefined => imports.find((item) => item.local === local);\n\nfunction unwrapSequenceCallee(node: Expression): Expression {\n if (\n node.type === 'SequenceExpression' &&\n node.expressions.length === 2 &&\n node.expressions[0]?.type === 'Literal' &&\n node.expressions[0].value === 0\n ) {\n return node.expressions[1] as Expression;\n }\n\n return node;\n}\n\nconst getExpressionImportKey = (node: Expression): string | null => {\n const expression = unwrapSequenceCallee(node);\n\n if (expression.type === 'Identifier') {\n return expression.name;\n }\n\n if (expression.type !== 'MemberExpression') {\n return null;\n }\n\n if (expression.object.type !== 'Identifier') {\n return null;\n }\n\n const propertyName = getMemberPropertyName(expression);\n return propertyName ? `${expression.object.name}.${propertyName}` : null;\n};\n\nconst isHookOrCreateElement = (name: string): boolean =>\n name === 'createElement' || /use[A-Z]/.test(name);\n\nconst getInnermostCallee = (call: CallExpression): Expression => {\n let callee = unwrapSequenceCallee(call.callee);\n while (callee.type === 'CallExpression') {\n callee = unwrapSequenceCallee(callee.callee);\n }\n\n return callee;\n};\n\nconst getImportForExpression = (\n node: Expression,\n imports: ImportBinding[]\n): [source: string, imported: string] | undefined => {\n const expression = unwrapSequenceCallee(node);\n const directMatchKey = getExpressionImportKey(expression);\n if (directMatchKey) {\n const directMatch = getImportBinding(imports, directMatchKey);\n if (directMatch) {\n return [directMatch.source, directMatch.imported];\n }\n }\n\n if (expression.type === 'Identifier') {\n const matched = getImportBinding(imports, expression.name);\n return matched ? [matched.source, matched.imported] : undefined;\n }\n\n if (expression.type !== 'MemberExpression') {\n return undefined;\n }\n\n if (expression.object.type !== 'Identifier') {\n return undefined;\n }\n\n const propertyName = getMemberPropertyName(expression);\n if (!propertyName) {\n return undefined;\n }\n\n const objectImport = getImportBinding(imports, expression.object.name);\n if (!objectImport) {\n return undefined;\n }\n\n if (\n objectImport.imported === 'default' ||\n objectImport.imported === '*' ||\n objectImport.source === 'react'\n ) {\n return [objectImport.source, propertyName];\n }\n\n return undefined;\n};\n\nconst isReactRuntimeCall = (\n call: CallExpression,\n imports: ImportBinding[]\n): boolean => {\n const callee = unwrapSequenceCallee(call.callee);\n const matched = getImportForExpression(callee, imports);\n if (!matched) {\n return false;\n }\n\n const [source, imported] = matched;\n if (jsxRuntimeSources.has(source)) {\n return true;\n }\n\n return source === 'react' && isHookOrCreateElement(imported);\n};\n\nconst isHocCall = (\n call: CallExpression,\n hocs: Record<string, string[]>,\n imports: ImportBinding[]\n): boolean => {\n const matched = getImportForExpression(getInnermostCallee(call), imports);\n return !!matched && hocs[matched[0]]?.includes(matched[1]);\n};\n\nconst isInsideHocCall = (\n ancestors: Node[],\n hocs: Record<string, string[]>,\n imports: ImportBinding[]\n): boolean =>\n ancestors.some(\n (ancestor): ancestor is CallExpression =>\n ancestor.type === 'CallExpression' && isHocCall(ancestor, hocs, imports)\n );\n\nconst getComponentTypes = (\n options?: CodeRemoverOptions\n): Record<string, string[]> => {\n const componentTypes = {\n ...(options?.componentTypes ?? { react: [defaultPlaceholder] }),\n };\n const reactTypes = componentTypes.react;\n\n if (Array.isArray(reactTypes) && reactTypes.includes(defaultPlaceholder)) {\n const idx = reactTypes.indexOf(defaultPlaceholder);\n componentTypes.react = [...reactTypes];\n componentTypes.react.splice(idx, 1, ...defaultReactComponentTypes);\n }\n\n return componentTypes;\n};\n\nconst getHocs = (options?: CodeRemoverOptions): Record<string, string[]> => {\n const hocs = {\n ...(options?.hocs ?? {}),\n };\n const reactHocs = new Set([...defaultReactHocs, ...(hocs.react ?? [])]);\n\n hocs.react = [...reactHocs];\n return hocs;\n};\n\nconst getTypeImport = (\n node: Node,\n imports: ImportBinding[]\n): [source: string, imported: string] | undefined => {\n if (node.type === 'Identifier') {\n const matched = getImportBinding(imports, node.name);\n return matched ? [matched.source, matched.imported] : undefined;\n }\n\n if (node.type !== 'TSQualifiedName') {\n return undefined;\n }\n\n if (node.left.type !== 'Identifier') {\n return undefined;\n }\n\n const matched = getImportBinding(imports, node.left.name);\n return matched ? [matched.source, node.right.name] : undefined;\n};\n\nconst isComponentTypeMatch = (\n id: Node,\n componentTypes: Record<string, string[]>,\n imports: ImportBinding[]\n): boolean => {\n if (id.type !== 'Identifier') {\n return false;\n }\n\n const annotation = id.typeAnnotation;\n if (\n !annotation ||\n annotation.type !== 'TSTypeAnnotation' ||\n annotation.typeAnnotation.type !== 'TSTypeReference'\n ) {\n return false;\n }\n\n const matched = getTypeImport(annotation.typeAnnotation.typeName, imports);\n return !!matched && componentTypes[matched[0]]?.includes(matched[1]);\n};\n\nconst getClassName = (node: Node): string | null =>\n node.type === 'ClassDeclaration' && node.id ? node.id.name : null;\n\nconst isFunctionLikeNode = (node: Node): node is OxcFunctionLikeNode =>\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression';\n\nconst isImmediatelyInvokedFunction = (\n fnNode: Node,\n ancestors: Node[],\n fnIndex: number\n): boolean => {\n // Walk past any ParenthesizedExpression / SequenceExpression wrappers that\n // sit between the function and its enclosing CallExpression. oxc-parser\n // preserves ParenthesizedExpression nodes, so `(() => {...})()` shows up\n // as CallExpression -> ParenthesizedExpression -> ArrowFunctionExpression.\n let child: Node = fnNode;\n for (let idx = fnIndex - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (\n ancestor.type === 'ParenthesizedExpression' &&\n 'expression' in ancestor &&\n ancestor.expression === child\n ) {\n child = ancestor;\n continue;\n }\n if (\n ancestor.type === 'SequenceExpression' &&\n Array.isArray(ancestor.expressions) &&\n ancestor.expressions[ancestor.expressions.length - 1] === child\n ) {\n child = ancestor;\n continue;\n }\n return ancestor.type === 'CallExpression' && ancestor.callee === child;\n }\n return false;\n};\n\n// A reference is \"deferred\" when it lives inside a function body that is\n// not immediately invoked. Module preeval reads exports without calling\n// them, so deferred references never run and must not be sanitized — that\n// would silently drop the binding (or remove the entire export) and break\n// importers that expect the function to be callable.\nconst isInDeferredFunctionScope = (ancestors: Node[]): boolean => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (!isFunctionLikeNode(ancestor)) {\n continue;\n }\n if (!isImmediatelyInvokedFunction(ancestor, ancestors, idx)) {\n return true;\n }\n }\n return false;\n};\n\nconst findFunctionReplacement = (ancestors: Node[]): Replacement | null => {\n const renderMethod = findLastAncestor(\n ancestors,\n (ancestor) =>\n ancestor.type === 'MethodDefinition' &&\n ancestor.key.type === 'Identifier' &&\n ancestor.key.name === 'render'\n );\n\n if (renderMethod) {\n const classDecl = findLastAncestor(\n ancestors,\n (ancestor) => ancestor.type === 'ClassDeclaration'\n );\n const className = classDecl ? getClassName(classDecl) : null;\n if (classDecl && className) {\n return {\n start: classDecl.start,\n end: classDecl.end,\n value: `function ${className}() { return null; }`,\n };\n }\n }\n\n const functionNode = findLastAncestor(ancestors, isFunctionLikeNode);\n\n if (!functionNode) {\n return null;\n }\n\n if (functionNode.type === 'ArrowFunctionExpression') {\n return {\n start: functionNode.start,\n end: functionNode.end,\n value: `${functionNode.async ? 'async ' : ''}() => { return null; }`,\n };\n }\n\n if (functionNode.type === 'FunctionDeclaration') {\n return {\n start: functionNode.start,\n end: functionNode.end,\n value: `${functionNode.async ? 'async ' : ''}function ${\n functionNode.id?.name ?? ''\n }() { return null; }`,\n };\n }\n\n return {\n start: functionNode.body.start,\n end: functionNode.body.end,\n value: '{ return null; }',\n };\n};\n\nconst normalizeReplacements = (replacements: Replacement[]): Replacement[] => {\n const sorted = [...replacements].sort((a, b) =>\n a.start === b.start ? b.end - a.end : a.start - b.start\n );\n const result: Replacement[] = [];\n\n sorted.forEach((replacement) => {\n const last = result[result.length - 1];\n if (\n last &&\n replacement.start >= last.start &&\n replacement.end <= last.end\n ) {\n return;\n }\n\n result.push(replacement);\n });\n\n return result;\n};\n\nexport const removeDangerousCodeWithOxc = (\n code: string,\n filename: string,\n options?: CodeRemoverOptions\n): string => {\n const replacements: Replacement[] = [];\n const derivedForbiddenBindings = new Set<string>();\n const program = parseOxc(code, filename);\n const imports = collectImportBindings(code, filename, program);\n const componentTypes = getComponentTypes(options);\n const hocs = getHocs(options);\n const hasHocs = Object.keys(hocs).length > 0;\n const windowScopedNames = windowTokenRe.test(code)\n ? collectWindowScopedNames(program)\n : new Set<string>();\n const reExportedLocalNames = collectReExportedLocalNames(program);\n\n const derivedBindingDiscovery = { found: true };\n while (derivedBindingDiscovery.found) {\n derivedBindingDiscovery.found = false;\n\n visit(program, createScope(null, 'root'), (node, scope) => {\n if (\n node.type !== 'VariableDeclarator' ||\n node.id.type !== 'Identifier' ||\n !node.init\n ) {\n return;\n }\n\n const bindingKey = getBindingKey(scope, node.id.name);\n if (!bindingKey || derivedForbiddenBindings.has(bindingKey)) {\n return;\n }\n\n if (\n containsForbiddenIdentifier(node.init) ||\n containsForbiddenReference(\n node.init,\n scope,\n windowScopedNames,\n derivedForbiddenBindings\n )\n ) {\n derivedForbiddenBindings.add(bindingKey);\n derivedBindingDiscovery.found = true;\n }\n });\n }\n\n visit(\n program,\n createScope(null, 'root'),\n (node, scope, parent, ancestors) => {\n if (node.type === 'JSXElement' || node.type === 'JSXFragment') {\n replacements.push(\n findFunctionReplacement(ancestors) ?? {\n start: node.start,\n end: node.end,\n value: 'null',\n }\n );\n return;\n }\n\n if (node.type === 'CallExpression') {\n if (isReactRuntimeCall(node, imports)) {\n const replacement = findFunctionReplacement(ancestors);\n if (replacement) {\n replacements.push(replacement);\n }\n\n return;\n }\n\n if (hasHocs && isHocCall(node, hocs, imports)) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: '() => null',\n });\n return;\n }\n }\n\n if (\n node.type === 'VariableDeclarator' &&\n node.id.type === 'Identifier' &&\n node.init &&\n isComponentTypeMatch(node.id, componentTypes, imports)\n ) {\n replacements.push({\n start: node.init.start,\n end: node.init.end,\n value: '() => null',\n });\n return;\n }\n\n if (\n node.type === 'UnaryExpression' &&\n node.operator === 'typeof' &&\n node.argument.type === 'Identifier' &&\n ssrCheckFields.has(node.argument.name) &&\n !hasBinding(scope, node.argument.name)\n ) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: '\"undefined\"',\n });\n return;\n }\n\n if (node.type === 'MetaProperty') {\n const owner = findRemovableOwner(node, ancestors);\n replacements.push({ start: owner.start, end: owner.end, value: '' });\n return;\n }\n\n if (\n node.type !== 'Identifier' ||\n isTypeContext(ancestors) ||\n isInsideTypeof(ancestors) ||\n isInsideImportDeclaration(ancestors)\n ) {\n return;\n }\n\n if (isPropertyOnlyIdentifier(node, parent)) {\n return;\n }\n\n const isAlwaysForbidden = alwaysForbiddenIdentifiers.has(node.name);\n const bindingKey = getBindingKey(scope, node.name);\n const isDerivedForbidden =\n bindingKey !== null && derivedForbiddenBindings.has(bindingKey);\n const isWindowScoped =\n windowScopedNames.has(node.name) && !hasBinding(scope, node.name);\n const isForbiddenGlobal =\n forbiddenGlobals.has(node.name) && !hasBinding(scope, node.name);\n\n if (\n !isAlwaysForbidden &&\n !isDerivedForbidden &&\n !isWindowScoped &&\n !isForbiddenGlobal\n ) {\n return;\n }\n\n if (!isAlwaysForbidden && isInDeferredFunctionScope(ancestors)) {\n return;\n }\n\n if (hasHocs && isInsideHocCall(ancestors, hocs, imports)) {\n return;\n }\n\n if (isBindingPosition(node, parent) && !isAlwaysForbidden) {\n return;\n }\n\n if (\n parent?.type === 'ExportDefaultDeclaration' &&\n parent.declaration === node\n ) {\n return;\n }\n\n if (\n generatedProcessorHelperNameRe.test(node.name) &&\n hasBinding(scope, node.name)\n ) {\n return;\n }\n\n const generatedHelperDeclarator = findLastAncestor(\n ancestors,\n (ancestor) =>\n ancestor.type === 'VariableDeclarator' &&\n ancestor.id.type === 'Identifier' &&\n generatedProcessorHelperNameRe.test(ancestor.id.name)\n );\n if (generatedHelperDeclarator) {\n return;\n }\n\n if (\n parent?.type === 'Property' &&\n parent.value === node &&\n hasBinding(scope, node.name)\n ) {\n return;\n }\n\n if (parent?.type === 'Property' && parent.value === node) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: parent.shorthand ? `${node.name}: undefined` : 'undefined',\n });\n return;\n }\n\n const grandparent = ancestors[ancestors.length - 2] ?? null;\n if (\n parent?.type === 'MemberExpression' &&\n parent.object === node &&\n grandparent?.type === 'SpreadElement' &&\n grandparent.argument === parent\n ) {\n replacements.push({\n start: grandparent.start,\n end: grandparent.end,\n value: '...{}',\n });\n return;\n }\n\n const exportProtection = findExportedBindingProtection(\n node,\n ancestors,\n reExportedLocalNames\n );\n if (exportProtection) {\n replacements.push(exportProtection);\n return;\n }\n\n const promiseOwner = findPromiseCallbackOwner(ancestors);\n const owner = promiseOwner\n ? findRemovableOwner(promiseOwner, ancestors)\n : findRemovableOwner(node, ancestors);\n replacements.push({ start: owner.start, end: owner.end, value: '' });\n }\n );\n\n return applyReplacements(code, normalizeReplacements(replacements));\n};\n"],"file":"oxcPreevalTransforms.js"}
@@ -1,5 +1,10 @@
1
1
  import { parseSync } from "oxc-parser";
2
- const MAX_PARSE_CACHE_ENTRIES = 200;
2
+ // 200 evicts under sustained pressure on large monorepos — the
3
+ // removeUnusedAfterReplacement cleanup loop reparses on every iteration
4
+ // (new content -> new key) and applyOxcProcessors reparses after extraction.
5
+ // 1000 is still bounded (~50-100 MB worst case for an enormous build) and
6
+ // keeps every entry hot across the actions for a single file.
7
+ const MAX_PARSE_CACHE_ENTRIES = 1e3;
3
8
  const parseCache = new Map();
4
9
  const getAstType = (filename) => filename.endsWith(".ts") || filename.endsWith(".tsx") ? "ts" : "js";
5
10
  const makeCacheKey = (filename, code, sourceType) => `${sourceType}\0${filename}\0${code}`;
@@ -1 +1 @@
1
- {"mappings":"AAAA,SAAS,iBAAiB;AAY1B,MAAM,0BAA0B;AAChC,MAAM,aAAa,IAAI,KAAwB;AAE/C,MAAM,cAAc,aAClB,SAAS,SAAS,MAAM,IAAI,SAAS,SAAS,OAAO,GAAG,OAAO;AAEjE,MAAM,gBACJ,UACA,MACA,eACW,GAAG,WAAW,IAAI,SAAS,IAAI;AAE5C,MAAM,kBAAkB,KAAa,UAAgC;AACnE,YAAW,IAAI,KAAK,MAAM;AAC1B,KAAI,WAAW,OAAO,yBAAyB;EAC7C,MAAM,YAAY,WAAW,MAAM,CAAC,MAAM,CAAC;AAC3C,MAAI,WAAW;AACb,cAAW,OAAO,UAAU;;;AAIhC,QAAO;;AAGT,OAAO,MAAM,kBACX,UACA,MACA,eACc;CACd,MAAM,WAAW,aAAa,UAAU,MAAM,WAAW;CACzD,MAAM,SAAS,WAAW,IAAI,SAAS;AACvC,KAAI,QAAQ;AACV,SAAO;;CAGT,MAAM,SAAS,UAAU,UAAU,MAAM;EACvC,SAAS,WAAW,SAAS;EAC7B,OAAO;EACP;EACD,CAAC;CACF,MAAM,aAAa,OAAO,OAAO,MAAM,UAAU,MAAM,aAAa,QAAQ;AAC5E,KAAI,YAAY;AACd,QAAM,IAAI,MAAM,WAAW,QAAQ;;AAGrC,QAAO,eAAe,UAAU;EAC9B,QAAQ,EACN,iBAAiB,OAAO,OAAO,iBAChC;EACD,SAAS,OAAO;EACjB,CAAC;;AAGJ,OAAO,MAAM,yBACX,UACA,MACA,eACY,eAAe,UAAU,MAAM,WAAW,CAAC","names":[],"sources":["../../src/utils/parseOxc.ts"],"version":3,"sourcesContent":["import { parseSync } from 'oxc-parser';\nimport type { Program } from 'oxc-parser';\n\ntype OxcSourceType = 'module' | 'unambiguous';\n\ntype ParsedOxc = {\n module: {\n hasModuleSyntax: boolean;\n };\n program: Program;\n};\n\nconst MAX_PARSE_CACHE_ENTRIES = 200;\nconst parseCache = new Map<string, ParsedOxc>();\n\nconst getAstType = (filename: string): 'js' | 'ts' =>\n filename.endsWith('.ts') || filename.endsWith('.tsx') ? 'ts' : 'js';\n\nconst makeCacheKey = (\n filename: string,\n code: string,\n sourceType: OxcSourceType\n): string => `${sourceType}\\0${filename}\\0${code}`;\n\nconst setCachedParse = (key: string, value: ParsedOxc): ParsedOxc => {\n parseCache.set(key, value);\n if (parseCache.size > MAX_PARSE_CACHE_ENTRIES) {\n const oldestKey = parseCache.keys().next().value;\n if (oldestKey) {\n parseCache.delete(oldestKey);\n }\n }\n\n return value;\n};\n\nexport const parseOxcCached = (\n filename: string,\n code: string,\n sourceType: OxcSourceType\n): ParsedOxc => {\n const cacheKey = makeCacheKey(filename, code, sourceType);\n const cached = parseCache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n const parsed = parseSync(filename, code, {\n astType: getAstType(filename),\n range: true,\n sourceType,\n });\n const fatalError = parsed.errors.find((error) => error.severity === 'Error');\n if (fatalError) {\n throw new Error(fatalError.message);\n }\n\n return setCachedParse(cacheKey, {\n module: {\n hasModuleSyntax: parsed.module.hasModuleSyntax,\n },\n program: parsed.program as Program,\n });\n};\n\nexport const parseOxcProgramCached = (\n filename: string,\n code: string,\n sourceType: OxcSourceType\n): Program => parseOxcCached(filename, code, sourceType).program;\n"],"file":"parseOxc.js"}
1
+ {"mappings":"AAAA,SAAS,iBAAiB;;;;;;AAiB1B,MAAM,0BAA0B;AAChC,MAAM,aAAa,IAAI,KAAwB;AAE/C,MAAM,cAAc,aAClB,SAAS,SAAS,MAAM,IAAI,SAAS,SAAS,OAAO,GAAG,OAAO;AAEjE,MAAM,gBACJ,UACA,MACA,eACW,GAAG,WAAW,IAAI,SAAS,IAAI;AAE5C,MAAM,kBAAkB,KAAa,UAAgC;AACnE,YAAW,IAAI,KAAK,MAAM;AAC1B,KAAI,WAAW,OAAO,yBAAyB;EAC7C,MAAM,YAAY,WAAW,MAAM,CAAC,MAAM,CAAC;AAC3C,MAAI,WAAW;AACb,cAAW,OAAO,UAAU;;;AAIhC,QAAO;;AAGT,OAAO,MAAM,kBACX,UACA,MACA,eACc;CACd,MAAM,WAAW,aAAa,UAAU,MAAM,WAAW;CACzD,MAAM,SAAS,WAAW,IAAI,SAAS;AACvC,KAAI,QAAQ;AACV,SAAO;;CAGT,MAAM,SAAS,UAAU,UAAU,MAAM;EACvC,SAAS,WAAW,SAAS;EAC7B,OAAO;EACP;EACD,CAAC;CACF,MAAM,aAAa,OAAO,OAAO,MAAM,UAAU,MAAM,aAAa,QAAQ;AAC5E,KAAI,YAAY;AACd,QAAM,IAAI,MAAM,WAAW,QAAQ;;AAGrC,QAAO,eAAe,UAAU;EAC9B,QAAQ,EACN,iBAAiB,OAAO,OAAO,iBAChC;EACD,SAAS,OAAO;EACjB,CAAC;;AAGJ,OAAO,MAAM,yBACX,UACA,MACA,eACY,eAAe,UAAU,MAAM,WAAW,CAAC","names":[],"sources":["../../src/utils/parseOxc.ts"],"version":3,"sourcesContent":["import { parseSync } from 'oxc-parser';\nimport type { Program } from 'oxc-parser';\n\ntype OxcSourceType = 'module' | 'unambiguous';\n\ntype ParsedOxc = {\n module: {\n hasModuleSyntax: boolean;\n };\n program: Program;\n};\n\n// 200 evicts under sustained pressure on large monorepos — the\n// removeUnusedAfterReplacement cleanup loop reparses on every iteration\n// (new content -> new key) and applyOxcProcessors reparses after extraction.\n// 1000 is still bounded (~50-100 MB worst case for an enormous build) and\n// keeps every entry hot across the actions for a single file.\nconst MAX_PARSE_CACHE_ENTRIES = 1000;\nconst parseCache = new Map<string, ParsedOxc>();\n\nconst getAstType = (filename: string): 'js' | 'ts' =>\n filename.endsWith('.ts') || filename.endsWith('.tsx') ? 'ts' : 'js';\n\nconst makeCacheKey = (\n filename: string,\n code: string,\n sourceType: OxcSourceType\n): string => `${sourceType}\\0${filename}\\0${code}`;\n\nconst setCachedParse = (key: string, value: ParsedOxc): ParsedOxc => {\n parseCache.set(key, value);\n if (parseCache.size > MAX_PARSE_CACHE_ENTRIES) {\n const oldestKey = parseCache.keys().next().value;\n if (oldestKey) {\n parseCache.delete(oldestKey);\n }\n }\n\n return value;\n};\n\nexport const parseOxcCached = (\n filename: string,\n code: string,\n sourceType: OxcSourceType\n): ParsedOxc => {\n const cacheKey = makeCacheKey(filename, code, sourceType);\n const cached = parseCache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n const parsed = parseSync(filename, code, {\n astType: getAstType(filename),\n range: true,\n sourceType,\n });\n const fatalError = parsed.errors.find((error) => error.severity === 'Error');\n if (fatalError) {\n throw new Error(fatalError.message);\n }\n\n return setCachedParse(cacheKey, {\n module: {\n hasModuleSyntax: parsed.module.hasModuleSyntax,\n },\n program: parsed.program as Program,\n });\n};\n\nexport const parseOxcProgramCached = (\n filename: string,\n code: string,\n sourceType: OxcSourceType\n): Program => parseOxcCached(filename, code, sourceType).program;\n"],"file":"parseOxc.js"}
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@wyw-in-js/transform",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@jridgewell/remapping": "^2.3.5",
7
- "@wyw-in-js/processor-utils": "2.0.0-alpha.1",
8
- "@wyw-in-js/shared": "2.0.0-alpha.1",
7
+ "@wyw-in-js/processor-utils": "2.0.0",
8
+ "@wyw-in-js/shared": "2.0.0",
9
9
  "cosmiconfig": "^8.0.0",
10
10
  "happy-dom": "^20.1.0",
11
11
  "minimatch": "^9.0.5",
12
- "oxc-parser": "0.127.0",
12
+ "oxc-parser": "0.131.0",
13
13
  "oxc-resolver": "11.19.1",
14
- "oxc-transform": "0.127.0",
14
+ "oxc-transform": "0.131.0",
15
15
  "source-map": "^0.7.4",
16
16
  "stylis": "^4.3.0",
17
17
  "ts-invariant": "^0.10.3"
@@ -27,6 +27,7 @@ export interface IPreevalResult {
27
27
  evalCode?: string;
28
28
  metadata: WYWTransformMetadata | null;
29
29
  processorClassNames?: Record<string, string>;
30
+ staticImportLocals?: string[];
30
31
  staticSideEffectImportLocals?: string[];
31
32
  staticDependencies?: string[];
32
33
  staticNullWYWMetaExtendsHelpers?: string[];
@@ -19,6 +19,7 @@ export function* collect() {
19
19
  }
20
20
  const result = collectOxcRuntime(loadedAndParsed.code, name, options.root ?? process.cwd(), {
21
21
  ...options.pluginOptions,
22
+ preserveSideEffectImportOrderLocals: new Set(preevalResult?.staticImportLocals ?? []),
22
23
  preserveSideEffectImportLocals: new Set(preevalResult?.staticSideEffectImportLocals ?? []),
23
24
  }, valueCache, options.inputSourceMap);
24
25
  return {
@@ -10,6 +10,6 @@ export declare const removeStaticHelperDeclarations: (code: string, filename: st
10
10
  removedImportLocals: Set<string>;
11
11
  };
12
12
  export declare const importSpecifierLocalName: (specifier: ImportDeclaration["specifiers"][number]) => string | null;
13
- export declare const removeUnusedStaticImports: (code: string, filename: string, staticImportLocals: Set<string>, sideEffectImportLocals: Set<string>) => string;
13
+ export declare const removeUnusedStaticImports: (code: string, filename: string, staticImportLocals: Set<string>, sideEffectImportLocals: Set<string>, sideEffectImportOrderLocals?: Set<string>) => string;
14
14
  export declare const replaceStaticWYWMetaExtendsHelpers: (code: string, filename: string, helperValues: Map<string, unknown>) => string;
15
15
  export declare const pruneStaticPreevalCode: (code: string, filename: string, staticValueNames: Set<string>, staticImportLocals: Set<string>, staticExtendsHelperValues: Map<string, unknown>, sideEffectImportLocals: Set<string>) => string;
@@ -131,7 +131,7 @@ export const removeStaticHelperDeclarations = (code, filename, staticValueNames)
131
131
  };
132
132
  };
133
133
  export const importSpecifierLocalName = (specifier) => specifier.local?.name ?? null;
134
- export const removeUnusedStaticImports = (code, filename, staticImportLocals, sideEffectImportLocals) => {
134
+ export const removeUnusedStaticImports = (code, filename, staticImportLocals, sideEffectImportLocals, sideEffectImportOrderLocals = sideEffectImportLocals) => {
135
135
  if (staticImportLocals.size === 0) {
136
136
  return code;
137
137
  }
@@ -139,11 +139,30 @@ export const removeUnusedStaticImports = (code, filename, staticImportLocals, si
139
139
  const used = collectUsedIdentifierNames(program);
140
140
  const ranges = [];
141
141
  const replacements = [];
142
+ const importSourceByLocal = new Map();
143
+ const removedSideEffectImportRanges = [];
144
+ const keptImportRangesBySource = new Map();
142
145
  program.body.forEach((statement) => {
143
146
  if (statement.type !== 'ImportDeclaration' ||
144
147
  statement.specifiers.length === 0) {
145
148
  return;
146
149
  }
150
+ const source = code.slice(statement.source.start, statement.source.end);
151
+ const orderedLocalNames = statement.specifiers.flatMap((specifier) => {
152
+ const localName = importSpecifierLocalName(specifier);
153
+ return localName && sideEffectImportOrderLocals.has(localName)
154
+ ? [localName]
155
+ : [];
156
+ });
157
+ const sideEffectLocalNames = statement.specifiers.flatMap((specifier) => {
158
+ const localName = importSpecifierLocalName(specifier);
159
+ return localName && sideEffectImportLocals.has(localName)
160
+ ? [localName]
161
+ : [];
162
+ });
163
+ [...orderedLocalNames, ...sideEffectLocalNames].forEach((localName) => {
164
+ importSourceByLocal.set(localName, source);
165
+ });
147
166
  const removable = statement.specifiers.flatMap((specifier, index) => {
148
167
  const localName = importSpecifierLocalName(specifier);
149
168
  return localName &&
@@ -153,14 +172,20 @@ export const removeUnusedStaticImports = (code, filename, staticImportLocals, si
153
172
  : [];
154
173
  });
155
174
  if (removable.length === 0) {
175
+ if (orderedLocalNames.length > 0 &&
176
+ !keptImportRangesBySource.has(source)) {
177
+ keptImportRangesBySource.set(source, {
178
+ end: statement.end,
179
+ start: statement.start,
180
+ });
181
+ }
156
182
  return;
157
183
  }
158
184
  if (removable.length === statement.specifiers.length) {
159
185
  if (removable.some((item) => sideEffectImportLocals.has(item.localName))) {
160
- replacements.push({
186
+ removedSideEffectImportRanges.push({
161
187
  end: statement.end,
162
188
  start: statement.start,
163
- text: `import ${code.slice(statement.source.start, statement.source.end)};`,
164
189
  });
165
190
  return;
166
191
  }
@@ -168,8 +193,75 @@ export const removeUnusedStaticImports = (code, filename, staticImportLocals, si
168
193
  end: statement.end,
169
194
  start: statement.start,
170
195
  });
196
+ return;
197
+ }
198
+ if (orderedLocalNames.length > 0 && !keptImportRangesBySource.has(source)) {
199
+ keptImportRangesBySource.set(source, {
200
+ end: statement.end,
201
+ start: statement.start,
202
+ });
171
203
  }
172
204
  });
205
+ if (removedSideEffectImportRanges.length > 0) {
206
+ const seenSources = new Set();
207
+ const removedRanges = removedSideEffectImportRanges.sort((a, b) => a.start - b.start);
208
+ const [firstRemoved, ...restRemoved] = removedRanges;
209
+ const pendingImports = [];
210
+ let insertionAfterLastKept = null;
211
+ let usedFirstRemovedRange = false;
212
+ const flushBefore = (position) => {
213
+ if (pendingImports.length === 0) {
214
+ return;
215
+ }
216
+ replacements.push({
217
+ end: position,
218
+ start: position,
219
+ text: `${pendingImports.join('\n')}\n`,
220
+ });
221
+ pendingImports.length = 0;
222
+ };
223
+ [...sideEffectImportOrderLocals].forEach((local) => {
224
+ const source = importSourceByLocal.get(local);
225
+ if (!source) {
226
+ return;
227
+ }
228
+ const keptRange = keptImportRangesBySource.get(source);
229
+ if (keptRange) {
230
+ flushBefore(keptRange.start);
231
+ insertionAfterLastKept = keptRange.end;
232
+ if (sideEffectImportLocals.has(local)) {
233
+ seenSources.add(source);
234
+ }
235
+ return;
236
+ }
237
+ if (!sideEffectImportLocals.has(local) || seenSources.has(source)) {
238
+ return;
239
+ }
240
+ seenSources.add(source);
241
+ pendingImports.push(`import ${source};`);
242
+ });
243
+ if (pendingImports.length > 0) {
244
+ if (insertionAfterLastKept !== null) {
245
+ replacements.push({
246
+ end: insertionAfterLastKept,
247
+ start: insertionAfterLastKept,
248
+ text: `\n${pendingImports.join('\n')}`,
249
+ });
250
+ }
251
+ else if (firstRemoved) {
252
+ usedFirstRemovedRange = true;
253
+ replacements.push({
254
+ end: firstRemoved.end,
255
+ start: firstRemoved.start,
256
+ text: pendingImports.join('\n'),
257
+ });
258
+ }
259
+ }
260
+ ranges.push(...(usedFirstRemovedRange ? restRemoved : removedRanges));
261
+ }
262
+ if (ranges.length > 1) {
263
+ ranges.sort((a, b) => a.start - b.start);
264
+ }
173
265
  return applyOxcReplacements(code, [
174
266
  ...ranges.map((range) => ({ ...range, text: '' })),
175
267
  ...replacements,
@@ -216,5 +308,5 @@ export const pruneStaticPreevalCode = (code, filename, staticValueNames, staticI
216
308
  ...staticImportLocals,
217
309
  ...helpersRemoved.removedImportLocals,
218
310
  ]);
219
- return removeUnusedStaticImports(helpersRemoved.code, filename, importLocalsToPrune, sideEffectImportLocals);
311
+ return removeUnusedStaticImports(helpersRemoved.code, filename, importLocalsToPrune, sideEffectImportLocals, new Set([...staticImportLocals, ...sideEffectImportLocals]));
220
312
  };
@@ -28,7 +28,7 @@ export function* resolveStaticOxcPreevalValues() {
28
28
  const staticOnly = evalStrategy === 'static';
29
29
  const staticValueCache = preevalResult.staticValueCache ?? new Map();
30
30
  const staticDependencies = new Set(preevalResult.staticDependencies ?? []);
31
- const staticImportLocals = new Set();
31
+ const staticImportLocals = new Set(preevalResult.staticImportLocals ?? []);
32
32
  const sideEffectImportLocals = new Set();
33
33
  const staticNullWYWMetaExtendsHelpers = new Set(preevalResult.staticNullWYWMetaExtendsHelpers ?? []);
34
34
  const memo = new Map();
@@ -180,6 +180,7 @@ export function* resolveStaticOxcPreevalValues() {
180
180
  preevalResult.baseCode = baseCode;
181
181
  preevalResult.code = appendOxcWywPreval(baseCode, filename, dependencyNames);
182
182
  preevalResult.evalCode = appendOxcWywPreval(evalBaseCode, filename, dependencyNames);
183
+ preevalResult.staticImportLocals = [...staticImportLocals];
183
184
  preevalResult.staticSideEffectImportLocals = [...sideEffectImportLocals];
184
185
  for (const dependency of staticDependencies) {
185
186
  const strippedDependency = stripQueryAndHash(dependency);
@@ -56,6 +56,7 @@ const ensureOxcPreevalResult = (services, item, originalAst) => {
56
56
  evalCode: result.code,
57
57
  metadata: result.metadata,
58
58
  processorClassNames: result.processorClassNames,
59
+ staticImportLocals: [],
59
60
  staticSideEffectImportLocals: [],
60
61
  staticDependencies: result.staticDependencies,
61
62
  staticValuesApplied: false,