@wyw-in-js/transform 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/module.js CHANGED
@@ -16,6 +16,7 @@ import NativeModule from 'module';
16
16
  import path from 'path';
17
17
  import vm from 'vm';
18
18
  import { invariant } from 'ts-invariant';
19
+ import { isFeatureEnabled } from '@wyw-in-js/shared';
19
20
  import './utils/dispose-polyfill';
20
21
  import { Entrypoint } from './transform/Entrypoint';
21
22
  import { getStack, isSuperSet } from './transform/Entrypoint.helpers';
@@ -119,7 +120,7 @@ export class Module {
119
120
  this.services = services;
120
121
  this.moduleImpl = moduleImpl;
121
122
  this.cache = services.cache;
122
- this.#entrypointRef = new WeakRef(entrypoint);
123
+ this.#entrypointRef = isFeatureEnabled(services.options.pluginOptions.features, 'useWeakRefInEval', entrypoint.name) ? new WeakRef(entrypoint) : entrypoint;
123
124
  this.idx = entrypoint.idx;
124
125
  this.id = entrypoint.name;
125
126
  this.filename = entrypoint.name;
@@ -143,7 +144,7 @@ export class Module {
143
144
  this.debug('the whole exports was overridden with %O', value);
144
145
  }
145
146
  get entrypoint() {
146
- const entrypoint = this.#entrypointRef.deref();
147
+ const entrypoint = this.#entrypointRef instanceof WeakRef ? this.#entrypointRef.deref() : this.#entrypointRef;
147
148
  invariant(entrypoint, `Module ${this.idx} is disposed`);
148
149
  return entrypoint;
149
150
  }
package/esm/module.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","names":["fs","NativeModule","path","vm","invariant","Entrypoint","getStack","isSuperSet","isUnprocessedEntrypointError","createVmContext","DefaultModuleImplementation","builtins","assert","buffer","child_process","cluster","console","constants","crypto","dgram","dns","domain","events","http","https","module","net","os","punycode","process","querystring","readline","repl","stream","string_decoder","sys","timers","tls","tty","url","util","zlib","NOOP","getUncached","cached","test","cachedSet","Set","split","has","filter","t","resolve","id","resolved","resolveDependency","Module","callstack","isEvaluated","require","Object","assign","debug","dependency","isAbsolute","Error","source","dependencies","push","entrypoint","getEntrypoint","only","evaluated","evaluatedOnly","exports","m","createChild","evaluate","ensure","bind","entrypointRef","constructor","services","parentModule","moduleImpl","cache","WeakRef","idx","name","filename","log","extend","parentIsIgnored","ignored","extensions","options","pluginOptions","value","deref","assertTransformed","get","evaluatedCreated","supersededWith","add","createEvaluated","transformedCode","JSON","parse","context","teardown","features","__wyw_dynamic_import","__dirname","dirname","overrideContext","script","Script","runInContext","e","EvalError","message","join","extension","extname","includes","newEntrypoint","readFileSync","stack","uncachedExports","length","code","createRoot","getDependency","Promise","_extensions","added","forEach","ext","_resolveFilename","paths","_nodeModulePaths"],"sources":["../src/module.ts"],"sourcesContent":["/**\n * This is a custom implementation for the module system for evaluating code,\n * used for resolving values for dependencies interpolated in `css` or `styled`.\n *\n * This serves 2 purposes:\n * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`\n * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds\n *\n * We also use it to transpile the code with Babel by default.\n * We also store source maps for it to provide correct error stacktraces.\n *\n */\n\nimport fs from 'fs';\nimport NativeModule from 'module';\nimport path from 'path';\nimport vm from 'vm';\n\nimport { invariant } from 'ts-invariant';\n\nimport type { Debugger } from '@wyw-in-js/shared';\n\nimport './utils/dispose-polyfill';\nimport type { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport { getStack, isSuperSet } from './transform/Entrypoint.helpers';\nimport type { IEntrypointDependency } from './transform/Entrypoint.types';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';\nimport type { Services } from './transform/types';\nimport { createVmContext } from './vm/createVmContext';\n\ntype HiddenModuleMembers = {\n _extensions: Record<string, () => void>;\n _resolveFilename: (\n id: string,\n options: { filename: string; id: string; paths: string[] }\n ) => string;\n _nodeModulePaths(filename: string): string[];\n};\n\nexport const DefaultModuleImplementation = NativeModule as typeof NativeModule &\n HiddenModuleMembers;\n\n// Supported node builtins based on the modules polyfilled by webpack\n// `true` means module is polyfilled, `false` means module is empty\nconst builtins = {\n assert: true,\n buffer: true,\n child_process: false,\n cluster: false,\n console: true,\n constants: true,\n crypto: true,\n dgram: false,\n dns: false,\n domain: true,\n events: true,\n fs: false,\n http: true,\n https: true,\n module: false,\n net: false,\n os: true,\n path: true,\n punycode: true,\n process: true,\n querystring: true,\n readline: false,\n repl: false,\n stream: true,\n string_decoder: true,\n sys: true,\n timers: true,\n tls: false,\n tty: true,\n url: true,\n util: true,\n vm: true,\n zlib: true,\n};\n\nconst NOOP = () => {};\n\nfunction getUncached(cached: string | string[], test: string[]): string[] {\n const cachedSet = new Set(\n typeof cached === 'string' ? cached.split(',') : cached\n );\n\n if (cachedSet.has('*')) {\n return [];\n }\n\n return test.filter((t) => !cachedSet.has(t));\n}\n\nfunction resolve(\n this: { resolveDependency: (id: string) => IEntrypointDependency },\n id: string\n): string {\n const { resolved } = this.resolveDependency(id);\n invariant(resolved, `Unable to resolve \"${id}\"`);\n return resolved;\n}\n\nexport class Module {\n public readonly callstack: string[] = [];\n\n public readonly debug: Debugger;\n\n public readonly dependencies: string[];\n\n public readonly extensions: string[];\n\n public readonly filename: string;\n\n public id: string;\n\n public readonly idx: string;\n\n public readonly ignored: boolean;\n\n public isEvaluated: boolean = false;\n\n public readonly parentIsIgnored: boolean;\n\n public require: {\n (id: string): unknown;\n ensure: () => void;\n resolve: (id: string) => string;\n } = Object.assign(\n (id: string) => {\n if (id in builtins) {\n // The module is in the allowed list of builtin node modules\n // Ideally we should prevent importing them, but webpack polyfills some\n // So we check for the list of polyfills to determine which ones to support\n if (builtins[id as keyof typeof builtins]) {\n this.debug('require', `builtin '${id}'`);\n return require(id);\n }\n\n return null;\n }\n\n // Resolve module id (and filename) relatively to parent module\n const dependency = this.resolveDependency(id);\n if (dependency.resolved === id && !path.isAbsolute(id)) {\n // The module is a builtin node modules, but not in the allowed list\n throw new Error(\n `Unable to import \"${id}\". Importing Node builtins is not supported in the sandbox.`\n );\n }\n\n invariant(\n dependency.resolved,\n `Dependency ${dependency.source} cannot be resolved`\n );\n\n this.dependencies.push(id);\n\n this.debug('require', `${id} -> ${dependency.resolved}`);\n\n const entrypoint = this.getEntrypoint(\n dependency.resolved,\n dependency.only,\n this.debug\n );\n\n if (entrypoint === null) {\n return dependency.resolved;\n }\n\n if (\n entrypoint.evaluated ||\n isSuperSet(entrypoint.evaluatedOnly, dependency.only)\n ) {\n return entrypoint.exports;\n }\n\n const m = this.createChild(entrypoint);\n m.evaluate();\n\n return entrypoint.exports;\n },\n {\n ensure: NOOP,\n resolve: resolve.bind(this),\n }\n );\n\n public resolve = resolve.bind(this);\n\n private cache: TransformCacheCollection;\n\n #entrypointRef: WeakRef<Entrypoint>;\n\n constructor(\n private services: Services,\n entrypoint: Entrypoint,\n parentModule?: Module,\n private moduleImpl: HiddenModuleMembers = DefaultModuleImplementation\n ) {\n this.cache = services.cache;\n this.#entrypointRef = new WeakRef(entrypoint);\n this.idx = entrypoint.idx;\n this.id = entrypoint.name;\n this.filename = entrypoint.name;\n this.dependencies = [];\n this.debug = entrypoint.log.extend('module');\n this.parentIsIgnored = parentModule?.ignored ?? false;\n this.ignored = entrypoint.ignored ?? this.parentIsIgnored;\n\n if (parentModule) {\n this.callstack = [entrypoint.name, ...parentModule.callstack];\n } else {\n this.callstack = [entrypoint.name];\n }\n\n this.extensions = services.options.pluginOptions.extensions;\n\n this.debug('init', entrypoint.name);\n }\n\n public get exports() {\n return this.entrypoint.exports;\n }\n\n public set exports(value) {\n this.entrypoint.exports = value;\n\n this.debug('the whole exports was overridden with %O', value);\n }\n\n protected get entrypoint(): Entrypoint {\n const entrypoint = this.#entrypointRef.deref();\n invariant(entrypoint, `Module ${this.idx} is disposed`);\n return entrypoint;\n }\n\n evaluate(): void {\n const { entrypoint } = this;\n entrypoint.assertTransformed();\n\n const cached = this.cache.get('entrypoints', entrypoint.name)!;\n let evaluatedCreated = false;\n if (!entrypoint.supersededWith) {\n this.cache.add(\n 'entrypoints',\n entrypoint.name,\n entrypoint.createEvaluated()\n );\n evaluatedCreated = true;\n }\n\n const { transformedCode: source } = entrypoint;\n const { pluginOptions } = this.services.options;\n\n if (!source) {\n this.debug(`evaluate`, 'there is nothing to evaluate');\n return;\n }\n\n if (this.isEvaluated) {\n this.debug('evaluate', `is already evaluated`);\n return;\n }\n\n this.debug('evaluate');\n this.debug.extend('source')('%s', source);\n\n this.isEvaluated = true;\n\n const { filename } = this;\n\n if (/\\.json$/.test(filename)) {\n // For JSON files, parse it to a JS object similar to Node\n this.exports = JSON.parse(source);\n return;\n }\n\n const { context, teardown } = createVmContext(\n filename,\n pluginOptions.features,\n {\n module: this,\n exports: entrypoint.exports,\n require: this.require,\n __wyw_dynamic_import: async (id: string) => this.require(id),\n __dirname: path.dirname(filename),\n },\n pluginOptions.overrideContext\n );\n\n try {\n const script = new vm.Script(\n `(function (exports) { ${source}\\n})(exports);`,\n {\n filename,\n }\n );\n\n script.runInContext(context);\n } catch (e) {\n this.isEvaluated = false;\n if (evaluatedCreated) {\n this.cache.add('entrypoints', entrypoint.name, cached);\n }\n\n if (isUnprocessedEntrypointError(e)) {\n // It will be handled by evalFile scenario\n throw e;\n }\n\n if (e instanceof EvalError) {\n this.debug('%O', e);\n\n throw e;\n }\n\n this.debug('%O\\n%O', e, this.callstack);\n throw new EvalError(\n `${(e as Error).message} in${this.callstack.join('\\n| ')}\\n`\n );\n } finally {\n teardown();\n }\n }\n\n getEntrypoint(\n filename: string,\n only: string[],\n log: Debugger\n ): Entrypoint | IEvaluatedEntrypoint | null {\n const extension = path.extname(filename);\n if (extension !== '.json' && !this.extensions.includes(extension)) {\n return null;\n }\n\n const entrypoint = this.cache.get('entrypoints', filename);\n if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {\n log('✅ file has been already evaluated');\n return entrypoint;\n }\n\n if (entrypoint?.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return entrypoint;\n }\n\n if (this.ignored) {\n log(\n '✅ one of the parent files has been ignored during prepare stage. Original code will be used'\n );\n\n const newEntrypoint = this.entrypoint.createChild(\n filename,\n ['*'],\n fs.readFileSync(filename, 'utf-8')\n );\n\n if (newEntrypoint === 'loop') {\n const stack = getStack(this.entrypoint);\n throw new Error(\n `Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`\n );\n }\n\n return newEntrypoint;\n }\n\n // Requested file can be already prepared for evaluation on the stage 1\n if (only && entrypoint) {\n const uncachedExports = getUncached(entrypoint.only ?? [], only);\n if (uncachedExports.length === 0) {\n log('✅ ready for evaluation');\n return entrypoint;\n }\n\n log(\n '❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)',\n uncachedExports,\n entrypoint.only\n );\n } else {\n log('❌ file has not been processed during prepare stage');\n }\n\n // If code wasn't extracted from cache, it indicates that we were unable\n // to process some of the imports on stage1. Let's try to reprocess.\n const code = fs.readFileSync(filename, 'utf-8');\n const newEntrypoint = Entrypoint.createRoot(\n this.services,\n filename,\n only,\n code\n );\n\n if (newEntrypoint.evaluated) {\n log('✅ file has been already evaluated');\n return newEntrypoint;\n }\n\n if (newEntrypoint.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return newEntrypoint;\n }\n\n return newEntrypoint;\n }\n\n resolveDependency = (id: string): IEntrypointDependency => {\n const cached = this.entrypoint.getDependency(id);\n invariant(!(cached instanceof Promise), 'Dependency is not resolved yet');\n\n if (cached) {\n return cached;\n }\n\n if (!this.ignored) {\n this.debug(\n '❌ import has not been resolved during prepare stage. Fallback to Node.js resolver'\n );\n }\n\n const extensions = this.moduleImpl._extensions;\n const added: string[] = [];\n\n try {\n // Check for supported extensions\n this.extensions.forEach((ext) => {\n if (ext in extensions) {\n return;\n }\n\n // When an extension is not supported, add it\n // And keep track of it to clean it up after resolving\n // Use noop for the transform function since we handle it\n extensions[ext] = NOOP;\n added.push(ext);\n });\n\n const { filename } = this;\n\n const resolved = this.moduleImpl._resolveFilename(id, {\n id: filename,\n filename,\n paths: this.moduleImpl._nodeModulePaths(path.dirname(filename)),\n });\n\n return {\n source: id,\n only: ['*'],\n resolved,\n };\n } finally {\n // Cleanup the extensions we added to restore previous behaviour\n added.forEach((ext) => delete extensions[ext]);\n }\n };\n\n protected createChild(entrypoint: Entrypoint): Module {\n return new Module(this.services, entrypoint, this, this.moduleImpl);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,YAAY,MAAM,QAAQ;AACjC,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,EAAE,MAAM,IAAI;AAEnB,SAASC,SAAS,QAAQ,cAAc;AAIxC,OAAO,0BAA0B;AAEjC,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SAASC,QAAQ,EAAEC,UAAU,QAAQ,gCAAgC;AAGrE,SAASC,4BAA4B,QAAQ,gDAAgD;AAE7F,SAASC,eAAe,QAAQ,sBAAsB;AAWtD,OAAO,MAAMC,2BAA2B,GAAGT,YACtB;;AAErB;AACA;AACA,MAAMU,QAAQ,GAAG;EACfC,MAAM,EAAE,IAAI;EACZC,MAAM,EAAE,IAAI;EACZC,aAAa,EAAE,KAAK;EACpBC,OAAO,EAAE,KAAK;EACdC,OAAO,EAAE,IAAI;EACbC,SAAS,EAAE,IAAI;EACfC,MAAM,EAAE,IAAI;EACZC,KAAK,EAAE,KAAK;EACZC,GAAG,EAAE,KAAK;EACVC,MAAM,EAAE,IAAI;EACZC,MAAM,EAAE,IAAI;EACZtB,EAAE,EAAE,KAAK;EACTuB,IAAI,EAAE,IAAI;EACVC,KAAK,EAAE,IAAI;EACXC,MAAM,EAAE,KAAK;EACbC,GAAG,EAAE,KAAK;EACVC,EAAE,EAAE,IAAI;EACRzB,IAAI,EAAE,IAAI;EACV0B,QAAQ,EAAE,IAAI;EACdC,OAAO,E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AEA,MAAMgC,UAAU,GAAG,IAAI,CAACV,UAAU,CAACkD,WAAW;IAC9C,MAAMC,KAAe,GAAG,EAAE;IAE1B,IAAI;MACF;MACA,IAAI,CAACzC,UAAU,CAAC0C,OAAO,CAAEC,GAAG,IAAK;QAC/B,IAAIA,GAAG,IAAI3C,UAAU,EAAE;UACrB;QACF;;QAEA;QACA;QACA;QACAA,UAAU,CAAC2C,GAAG,CAAC,GAAG/F,IAAI;QACtB6F,KAAK,CAACnE,IAAI,CAACqE,GAAG,CAAC;MACjB,CAAC,CAAC;MAEF,MAAM;QAAEhD;MAAS,CAAC,GAAG,IAAI;MAEzB,MAAMnC,QAAQ,GAAG,IAAI,CAAC8B,UAAU,CAACsD,gBAAgB,CAACrF,EAAE,EAAE;QACpDA,EAAE,EAAEoC,QAAQ;QACZA,QAAQ;QACRkD,KAAK,EAAE,IAAI,CAACvD,UAAU,CAACwD,gBAAgB,CAAC1I,IAAI,CAAC+G,OAAO,CAACxB,QAAQ,CAAC;MAChE,CAAC,CAAC;MAEF,OAAO;QACLvB,MAAM,EAAEb,EAAE;QACVkB,IAAI,EAAE,CAAC,GAAG,CAAC;QACXjB;MACF,CAAC;IACH,CAAC,SAAS;MACR;MACAiF,KAAK,CAACC,OAAO,CAAEC,GAAG,IAAK,OAAO3C,UAAU,CAAC2C,GAAG,CAAC,CAAC;IAChD;EACF,CAAC;EAES7D,WAAWA,CAACP,UAAsB,EAAU;IACpD,OAAO,IAAIb,MAAM,CAAC,IAAI,CAAC0B,QAAQ,EAAEb,UAAU,EAAE,IAAI,EAAE,IAAI,CAACe,UAAU,CAAC;EACrE;AACF"}
1
+ {"version":3,"file":"module.js","names":["fs","NativeModule","path","vm","invariant","isFeatureEnabled","Entrypoint","getStack","isSuperSet","isUnprocessedEntrypointError","createVmContext","DefaultModuleImplementation","builtins","assert","buffer","child_process","cluster","console","constants","crypto","dgram","dns","domain","events","http","https","module","net","os","punycode","process","querystring","readline","repl","stream","string_decoder","sys","timers","tls","tty","url","util","zlib","NOOP","getUncached","cached","test","cachedSet","Set","split","has","filter","t","resolve","id","resolved","resolveDependency","Module","callstack","isEvaluated","require","Object","assign","debug","dependency","isAbsolute","Error","source","dependencies","push","entrypoint","getEntrypoint","only","evaluated","evaluatedOnly","exports","m","createChild","evaluate","ensure","bind","entrypointRef","constructor","services","parentModule","moduleImpl","cache","options","pluginOptions","features","name","WeakRef","idx","filename","log","extend","parentIsIgnored","ignored","extensions","value","deref","assertTransformed","get","evaluatedCreated","supersededWith","add","createEvaluated","transformedCode","JSON","parse","context","teardown","__wyw_dynamic_import","__dirname","dirname","overrideContext","script","Script","runInContext","e","EvalError","message","join","extension","extname","includes","newEntrypoint","readFileSync","stack","uncachedExports","length","code","createRoot","getDependency","Promise","_extensions","added","forEach","ext","_resolveFilename","paths","_nodeModulePaths"],"sources":["../src/module.ts"],"sourcesContent":["/**\n * This is a custom implementation for the module system for evaluating code,\n * used for resolving values for dependencies interpolated in `css` or `styled`.\n *\n * This serves 2 purposes:\n * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`\n * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds\n *\n * We also use it to transpile the code with Babel by default.\n * We also store source maps for it to provide correct error stacktraces.\n *\n */\n\nimport fs from 'fs';\nimport NativeModule from 'module';\nimport path from 'path';\nimport vm from 'vm';\n\nimport { invariant } from 'ts-invariant';\n\nimport { isFeatureEnabled, type Debugger } from '@wyw-in-js/shared';\n\nimport './utils/dispose-polyfill';\nimport type { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport { getStack, isSuperSet } from './transform/Entrypoint.helpers';\nimport type { IEntrypointDependency } from './transform/Entrypoint.types';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';\nimport type { Services } from './transform/types';\nimport { createVmContext } from './vm/createVmContext';\n\ntype HiddenModuleMembers = {\n _extensions: Record<string, () => void>;\n _resolveFilename: (\n id: string,\n options: { filename: string; id: string; paths: string[] }\n ) => string;\n _nodeModulePaths(filename: string): string[];\n};\n\nexport const DefaultModuleImplementation = NativeModule as typeof NativeModule &\n HiddenModuleMembers;\n\n// Supported node builtins based on the modules polyfilled by webpack\n// `true` means module is polyfilled, `false` means module is empty\nconst builtins = {\n assert: true,\n buffer: true,\n child_process: false,\n cluster: false,\n console: true,\n constants: true,\n crypto: true,\n dgram: false,\n dns: false,\n domain: true,\n events: true,\n fs: false,\n http: true,\n https: true,\n module: false,\n net: false,\n os: true,\n path: true,\n punycode: true,\n process: true,\n querystring: true,\n readline: false,\n repl: false,\n stream: true,\n string_decoder: true,\n sys: true,\n timers: true,\n tls: false,\n tty: true,\n url: true,\n util: true,\n vm: true,\n zlib: true,\n};\n\nconst NOOP = () => {};\n\nfunction getUncached(cached: string | string[], test: string[]): string[] {\n const cachedSet = new Set(\n typeof cached === 'string' ? cached.split(',') : cached\n );\n\n if (cachedSet.has('*')) {\n return [];\n }\n\n return test.filter((t) => !cachedSet.has(t));\n}\n\nfunction resolve(\n this: { resolveDependency: (id: string) => IEntrypointDependency },\n id: string\n): string {\n const { resolved } = this.resolveDependency(id);\n invariant(resolved, `Unable to resolve \"${id}\"`);\n return resolved;\n}\n\nexport class Module {\n public readonly callstack: string[] = [];\n\n public readonly debug: Debugger;\n\n public readonly dependencies: string[];\n\n public readonly extensions: string[];\n\n public readonly filename: string;\n\n public id: string;\n\n public readonly idx: string;\n\n public readonly ignored: boolean;\n\n public isEvaluated: boolean = false;\n\n public readonly parentIsIgnored: boolean;\n\n public require: {\n (id: string): unknown;\n ensure: () => void;\n resolve: (id: string) => string;\n } = Object.assign(\n (id: string) => {\n if (id in builtins) {\n // The module is in the allowed list of builtin node modules\n // Ideally we should prevent importing them, but webpack polyfills some\n // So we check for the list of polyfills to determine which ones to support\n if (builtins[id as keyof typeof builtins]) {\n this.debug('require', `builtin '${id}'`);\n return require(id);\n }\n\n return null;\n }\n\n // Resolve module id (and filename) relatively to parent module\n const dependency = this.resolveDependency(id);\n if (dependency.resolved === id && !path.isAbsolute(id)) {\n // The module is a builtin node modules, but not in the allowed list\n throw new Error(\n `Unable to import \"${id}\". Importing Node builtins is not supported in the sandbox.`\n );\n }\n\n invariant(\n dependency.resolved,\n `Dependency ${dependency.source} cannot be resolved`\n );\n\n this.dependencies.push(id);\n\n this.debug('require', `${id} -> ${dependency.resolved}`);\n\n const entrypoint = this.getEntrypoint(\n dependency.resolved,\n dependency.only,\n this.debug\n );\n\n if (entrypoint === null) {\n return dependency.resolved;\n }\n\n if (\n entrypoint.evaluated ||\n isSuperSet(entrypoint.evaluatedOnly, dependency.only)\n ) {\n return entrypoint.exports;\n }\n\n const m = this.createChild(entrypoint);\n m.evaluate();\n\n return entrypoint.exports;\n },\n {\n ensure: NOOP,\n resolve: resolve.bind(this),\n }\n );\n\n public resolve = resolve.bind(this);\n\n private cache: TransformCacheCollection;\n\n #entrypointRef: WeakRef<Entrypoint> | Entrypoint;\n\n constructor(\n private services: Services,\n entrypoint: Entrypoint,\n parentModule?: Module,\n private moduleImpl: HiddenModuleMembers = DefaultModuleImplementation\n ) {\n this.cache = services.cache;\n this.#entrypointRef = isFeatureEnabled(\n services.options.pluginOptions.features,\n 'useWeakRefInEval',\n entrypoint.name\n )\n ? new WeakRef(entrypoint)\n : entrypoint;\n this.idx = entrypoint.idx;\n this.id = entrypoint.name;\n this.filename = entrypoint.name;\n this.dependencies = [];\n this.debug = entrypoint.log.extend('module');\n this.parentIsIgnored = parentModule?.ignored ?? false;\n this.ignored = entrypoint.ignored ?? this.parentIsIgnored;\n\n if (parentModule) {\n this.callstack = [entrypoint.name, ...parentModule.callstack];\n } else {\n this.callstack = [entrypoint.name];\n }\n\n this.extensions = services.options.pluginOptions.extensions;\n\n this.debug('init', entrypoint.name);\n }\n\n public get exports() {\n return this.entrypoint.exports;\n }\n\n public set exports(value) {\n this.entrypoint.exports = value;\n\n this.debug('the whole exports was overridden with %O', value);\n }\n\n protected get entrypoint(): Entrypoint {\n const entrypoint =\n this.#entrypointRef instanceof WeakRef\n ? this.#entrypointRef.deref()\n : this.#entrypointRef;\n invariant(entrypoint, `Module ${this.idx} is disposed`);\n return entrypoint;\n }\n\n evaluate(): void {\n const { entrypoint } = this;\n entrypoint.assertTransformed();\n\n const cached = this.cache.get('entrypoints', entrypoint.name)!;\n let evaluatedCreated = false;\n if (!entrypoint.supersededWith) {\n this.cache.add(\n 'entrypoints',\n entrypoint.name,\n entrypoint.createEvaluated()\n );\n evaluatedCreated = true;\n }\n\n const { transformedCode: source } = entrypoint;\n const { pluginOptions } = this.services.options;\n\n if (!source) {\n this.debug(`evaluate`, 'there is nothing to evaluate');\n return;\n }\n\n if (this.isEvaluated) {\n this.debug('evaluate', `is already evaluated`);\n return;\n }\n\n this.debug('evaluate');\n this.debug.extend('source')('%s', source);\n\n this.isEvaluated = true;\n\n const { filename } = this;\n\n if (/\\.json$/.test(filename)) {\n // For JSON files, parse it to a JS object similar to Node\n this.exports = JSON.parse(source);\n return;\n }\n\n const { context, teardown } = createVmContext(\n filename,\n pluginOptions.features,\n {\n module: this,\n exports: entrypoint.exports,\n require: this.require,\n __wyw_dynamic_import: async (id: string) => this.require(id),\n __dirname: path.dirname(filename),\n },\n pluginOptions.overrideContext\n );\n\n try {\n const script = new vm.Script(\n `(function (exports) { ${source}\\n})(exports);`,\n {\n filename,\n }\n );\n\n script.runInContext(context);\n } catch (e) {\n this.isEvaluated = false;\n if (evaluatedCreated) {\n this.cache.add('entrypoints', entrypoint.name, cached);\n }\n\n if (isUnprocessedEntrypointError(e)) {\n // It will be handled by evalFile scenario\n throw e;\n }\n\n if (e instanceof EvalError) {\n this.debug('%O', e);\n\n throw e;\n }\n\n this.debug('%O\\n%O', e, this.callstack);\n throw new EvalError(\n `${(e as Error).message} in${this.callstack.join('\\n| ')}\\n`\n );\n } finally {\n teardown();\n }\n }\n\n getEntrypoint(\n filename: string,\n only: string[],\n log: Debugger\n ): Entrypoint | IEvaluatedEntrypoint | null {\n const extension = path.extname(filename);\n if (extension !== '.json' && !this.extensions.includes(extension)) {\n return null;\n }\n\n const entrypoint = this.cache.get('entrypoints', filename);\n if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {\n log('✅ file has been already evaluated');\n return entrypoint;\n }\n\n if (entrypoint?.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return entrypoint;\n }\n\n if (this.ignored) {\n log(\n '✅ one of the parent files has been ignored during prepare stage. Original code will be used'\n );\n\n const newEntrypoint = this.entrypoint.createChild(\n filename,\n ['*'],\n fs.readFileSync(filename, 'utf-8')\n );\n\n if (newEntrypoint === 'loop') {\n const stack = getStack(this.entrypoint);\n throw new Error(\n `Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`\n );\n }\n\n return newEntrypoint;\n }\n\n // Requested file can be already prepared for evaluation on the stage 1\n if (only && entrypoint) {\n const uncachedExports = getUncached(entrypoint.only ?? [], only);\n if (uncachedExports.length === 0) {\n log('✅ ready for evaluation');\n return entrypoint;\n }\n\n log(\n '❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)',\n uncachedExports,\n entrypoint.only\n );\n } else {\n log('❌ file has not been processed during prepare stage');\n }\n\n // If code wasn't extracted from cache, it indicates that we were unable\n // to process some of the imports on stage1. Let's try to reprocess.\n const code = fs.readFileSync(filename, 'utf-8');\n const newEntrypoint = Entrypoint.createRoot(\n this.services,\n filename,\n only,\n code\n );\n\n if (newEntrypoint.evaluated) {\n log('✅ file has been already evaluated');\n return newEntrypoint;\n }\n\n if (newEntrypoint.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return newEntrypoint;\n }\n\n return newEntrypoint;\n }\n\n resolveDependency = (id: string): IEntrypointDependency => {\n const cached = this.entrypoint.getDependency(id);\n invariant(!(cached instanceof Promise), 'Dependency is not resolved yet');\n\n if (cached) {\n return cached;\n }\n\n if (!this.ignored) {\n this.debug(\n '❌ import has not been resolved during prepare stage. Fallback to Node.js resolver'\n );\n }\n\n const extensions = this.moduleImpl._extensions;\n const added: string[] = [];\n\n try {\n // Check for supported extensions\n this.extensions.forEach((ext) => {\n if (ext in extensions) {\n return;\n }\n\n // When an extension is not supported, add it\n // And keep track of it to clean it up after resolving\n // Use noop for the transform function since we handle it\n extensions[ext] = NOOP;\n added.push(ext);\n });\n\n const { filename } = this;\n\n const resolved = this.moduleImpl._resolveFilename(id, {\n id: filename,\n filename,\n paths: this.moduleImpl._nodeModulePaths(path.dirname(filename)),\n });\n\n return {\n source: id,\n only: ['*'],\n resolved,\n };\n } finally {\n // Cleanup the extensions we added to restore previous behaviour\n added.forEach((ext) => delete extensions[ext]);\n }\n };\n\n protected createChild(entrypoint: Entrypoint): Module {\n return new Module(this.services, entrypoint, this, this.moduleImpl);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,YAAY,MAAM,QAAQ;AACjC,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,EAAE,MAAM,IAAI;AAEnB,SAASC,SAAS,QAAQ,cAAc;AAExC,SAASC,gBAAgB,QAAuB,mBAAmB;AAEnE,OAAO,0BAA0B;AAEjC,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SAASC,QAAQ,EAAEC,UAAU,QAAQ,gCAAgC;AAGrE,SAASC,4BAA4B,QAAQ,gDAAgD;AAE7F,SAASC,eAAe,QAAQ,sBAAsB;AAWtD,OAAO,MAAMC,2BAA2B,GAAGV,YACtB;;AAErB;AACA;AACA,MAAMW,QAAQ,GAAG;EACfC,MAAM,EAAE,IAAI;EACZC,MAAM,EAAE,IAAI;EACZC,aAAa,EAAE,KAAK;EACpBC,OAAO,EAAE,KAAK;EACdC,OAAO,EAAE,IAAI;EACbC,SAAS,EAAE,IAAI;EACfC,MAAM,EAAE,IAAI;EACZC,KAAK,EAAE,KAAK;EAC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AS;MACR;MACAiF,KAAK,CAACC,OAAO,CAAEC,GAAG,IAAK,OAAOxC,UAAU,CAACwC,GAAG,CAAC,CAAC;IAChD;EACF,CAAC;EAES7D,WAAWA,CAACP,UAAsB,EAAU;IACpD,OAAO,IAAIb,MAAM,CAAC,IAAI,CAAC0B,QAAQ,EAAEb,UAAU,EAAE,IAAI,EAAE,IAAI,CAACe,UAAU,CAAC;EACrE;AACF"}
@@ -26,7 +26,8 @@ export function loadWywOptions(overrides = defaultOverrides) {
26
26
  globalCache: true,
27
27
  happyDOM: true,
28
28
  softErrors: false,
29
- useBabelConfigs: true
29
+ useBabelConfigs: true,
30
+ useWeakRefInEval: true
30
31
  };
31
32
  const options = {
32
33
  displayName: false,
@@ -1 +1 @@
1
- {"version":3,"file":"loadWywOptions.js","names":["cosmiconfigSync","shaker","searchPlaces","explorerSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","options","displayName","evaluate","extensions","action","test","filename","code","highPriorityPlugins","config","features","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\n\nimport { shaker } from '../../shaker';\nimport type { PluginOptions } from '../../types';\n\nconst searchPlaces = [\n `.wyw-in-jsrc`,\n `.wyw-in-jsrc.json`,\n `.wyw-in-jsrc.yaml`,\n `.wyw-in-jsrc.yml`,\n `.wyw-in-jsrc.js`,\n `.wyw-in-jsrc.cjs`,\n `.config/wyw-in-jsrc`,\n `.config/wyw-in-jsrc.json`,\n `.config/wyw-in-jsrc.yaml`,\n `.config/wyw-in-jsrc.yml`,\n `.config/wyw-in-jsrc.js`,\n `.config/wyw-in-jsrc.cjs`,\n `wyw-in-js.config.js`,\n `wyw-in-js.config.cjs`,\n];\n\nconst explorerSync = cosmiconfigSync('wyw-in-js', { searchPlaces });\n\nexport type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {\n features?: Partial<FeatureFlags>;\n};\n\nconst cache = new WeakMap<Partial<PartialOptions>, StrictOptions>();\nconst defaultOverrides = {};\nconst nodeModulesRegExp = /[\\\\/]node_modules[\\\\/]/;\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const { configFile, ignore, rules, babelOptions = {}, ...rest } = overrides;\n\n const result =\n // eslint-disable-next-line no-nested-ternary\n configFile === false\n ? undefined\n : configFile !== undefined\n ? explorerSync.load(configFile)\n : explorerSync.search();\n\n const defaultFeatures: FeatureFlags = {\n dangerousCodeRemover: true,\n globalCache: true,\n happyDOM: true,\n softErrors: false,\n useBabelConfigs: true,\n };\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n rules: rules ?? [\n {\n action: shaker,\n },\n {\n // The old `ignore` option is used as a default value for `ignore` rule.\n test: ignore ?? nodeModulesRegExp,\n action: 'ignore',\n },\n {\n // Do not ignore ES-modules\n test: (filename, code) => {\n if (!nodeModulesRegExp.test(filename)) {\n return false;\n }\n\n // If a file contains `export` or `import` keywords, we assume it's an ES-module\n return /(?:^|\\*\\/|;|})\\s*(?:export|import)[\\s{]/m.test(code);\n },\n action: shaker,\n },\n ],\n babelOptions,\n highPriorityPlugins: ['module-resolver'],\n ...(result ? result.config : {}),\n ...rest,\n features: {\n ...defaultFeatures,\n ...(result ? result.config.features : {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,aAAa;AAI7C,SAASC,MAAM,QAAQ,cAAc;AAGrC,MAAMC,YAAY,GAAG,CAClB,cAAa,EACb,mBAAkB,EAClB,mBAAkB,EAClB,k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MACEiB,MAAM,EAAE9B;IACV,CAAC,EACD;MACE;MACA+B,IAAI,EAAEnB,MAAM,IAAIN,iBAAiB;MACjCwB,MAAM,EAAE;IACV,CAAC,EACD;MACE;MACAC,IAAI,EAAEA,CAACC,QAAQ,EAAEC,IAAI,KAAK;QACxB,IAAI,CAAC3B,iBAAiB,CAACyB,IAAI,CAACC,QAAQ,CAAC,EAAE;UACrC,OAAO,KAAK;QACd;;QAEA;QACA,OAAO,0CAA0C,CAACD,IAAI,CAACE,IAAI,CAAC;MAC9D,CAAC;MACDH,MAAM,EAAE9B;IACV,CAAC,CACF;IACDc,YAAY;IACZoB,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;IACxC,IAAIlB,MAAM,GAAGA,MAAM,CAACmB,MAAM,GAAG,CAAC,CAAC,CAAC;IAChC,GAAGpB,IAAI;IACPqB,QAAQ,EAAE;MACR,GAAGhB,eAAe;MAClB,IAAIJ,MAAM,GAAGA,MAAM,CAACmB,MAAM,CAACC,QAAQ,GAAG,CAAC,CAAC,CAAC;MACzC,GAAGrB,IAAI,CAACqB;IACV;EACF,CAAC;EAEDjC,KAAK,CAACkC,GAAG,CAAC7B,SAAS,EAAEkB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB"}
1
+ {"version":3,"file":"loadWywOptions.js","names":["cosmiconfigSync","shaker","searchPlaces","explorerSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","useWeakRefInEval","options","displayName","evaluate","extensions","action","test","filename","code","highPriorityPlugins","config","features","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\n\nimport { shaker } from '../../shaker';\nimport type { PluginOptions } from '../../types';\n\nconst searchPlaces = [\n `.wyw-in-jsrc`,\n `.wyw-in-jsrc.json`,\n `.wyw-in-jsrc.yaml`,\n `.wyw-in-jsrc.yml`,\n `.wyw-in-jsrc.js`,\n `.wyw-in-jsrc.cjs`,\n `.config/wyw-in-jsrc`,\n `.config/wyw-in-jsrc.json`,\n `.config/wyw-in-jsrc.yaml`,\n `.config/wyw-in-jsrc.yml`,\n `.config/wyw-in-jsrc.js`,\n `.config/wyw-in-jsrc.cjs`,\n `wyw-in-js.config.js`,\n `wyw-in-js.config.cjs`,\n];\n\nconst explorerSync = cosmiconfigSync('wyw-in-js', { searchPlaces });\n\nexport type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {\n features?: Partial<FeatureFlags>;\n};\n\nconst cache = new WeakMap<Partial<PartialOptions>, StrictOptions>();\nconst defaultOverrides = {};\nconst nodeModulesRegExp = /[\\\\/]node_modules[\\\\/]/;\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const { configFile, ignore, rules, babelOptions = {}, ...rest } = overrides;\n\n const result =\n // eslint-disable-next-line no-nested-ternary\n configFile === false\n ? undefined\n : configFile !== undefined\n ? explorerSync.load(configFile)\n : explorerSync.search();\n\n const defaultFeatures: FeatureFlags = {\n dangerousCodeRemover: true,\n globalCache: true,\n happyDOM: true,\n softErrors: false,\n useBabelConfigs: true,\n useWeakRefInEval: true,\n };\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n rules: rules ?? [\n {\n action: shaker,\n },\n {\n // The old `ignore` option is used as a default value for `ignore` rule.\n test: ignore ?? nodeModulesRegExp,\n action: 'ignore',\n },\n {\n // Do not ignore ES-modules\n test: (filename, code) => {\n if (!nodeModulesRegExp.test(filename)) {\n return false;\n }\n\n // If a file contains `export` or `import` keywords, we assume it's an ES-module\n return /(?:^|\\*\\/|;|})\\s*(?:export|import)[\\s{]/m.test(code);\n },\n action: shaker,\n },\n ],\n babelOptions,\n highPriorityPlugins: ['module-resolver'],\n ...(result ? result.config : {}),\n ...rest,\n features: {\n ...defaultFeatures,\n ...(result ? result.config.features : {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,aAAa;AAI7C,SAASC,MAAM,QAAQ,cAAc;AAGrC,MAAMC,YAAY,GAAG,CAClB,cAAa,EACb,mBAAkB,EAClB,mBAAkB,EAClB,kBAAiB,EACjB,iBAAgB,EAChB,kBAAiB,EACjB,qBAAoB,EACpB,0BAAyB,EACzB,0BAAyB,EACzB,yBAAwB,EACxB,wBAAuB,EACvB,yBAAwB,EACxB,qBAAoB,EACpB,sBAAqB,CACvB;AAED,MAAMC,YAAY,GAAGH,eAAe,CAAC,WAAW,EAAE;EAAEE;AAAa,CAAC,CAAC;AAMnE,MAAME,KAAK,GAAG,IAAIC,OAAO,CAAyC,CAAC;AACnE,MAAMC,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAMC,iBAAiB,GAAG,wBAAwB;AAElD,OAAO,SAASC,cAAcA,CAC5BC,SAAyB,GAAGH,gBAAgB,EAC7B;EACf,IAAIF,KAAK,CAACM,GAAG,CAACD,SAAS,CAAC,EAAE;IACxB,OAAOL,KAAK,CAACO,GAAG,CAACF,SAAS,CAAC;EAC7B;EAEA,MAAM;IAAEG,UAAU;IAAEC,MAAM;IAAEC,KAAK;IAAEC,YAAY,GAAG,CAAC,CAAC;IAAE,GAAGC;EAAK,CAAC,GAAGP,SAAS;EAE3E,MAAMQ,MAAM;EACV;EACAL,UAAU,KAAK,KAAK,GAChBM,SAAS,GACTN,UAAU,KAAKM,SAAS,GACxBf,YAAY,CAACgB,IAAI,CAACP,UAAU,CAAC,GAC7BT,YAAY,CAACiB,MAAM,CAAC,CAAC;EAE3B,MAAMC,eAA6B,GAAG;IACpCC,oBAAoB,EAAE,IAAI;IAC1BC,WAAW,EAAE,IAAI;IACjBC,QAAQ,EAAE,IAAI;IACdC,UAAU,EAAE,KAAK;IACjBC,eAAe,EAAE,IAAI;IACrBC,gBAAgB,EAAE;EACpB,CAAC;EAED,MAAMC,OAAsB,GAAG;IAC7BC,WAAW,EAAE,KAAK;IAClBC,QAAQ,EAAE,IAAI;IACdC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;IAC1EjB,KAAK,EAAEA,KAAK,IAAI,CACd;MACEkB,MAAM,EAAE/B;IACV,CAAC,EACD;MACE;MACAgC,IAAI,EAAEpB,MAAM,IAAIN,iBAAiB;MACjCyB,MAAM,EAAE;IACV,CAAC,EACD;MACE;MACAC,IAAI,EAAEA,CAACC,QAAQ,EAAEC,IAAI,KAAK;QACxB,IAAI,CAAC5B,iBAAiB,CAAC0B,IAAI,CAACC,QAAQ,CAAC,EAAE;UACrC,OAAO,KAAK;QACd;;QAEA;QACA,OAAO,0CAA0C,CAACD,IAAI,CAACE,IAAI,CAAC;MAC9D,CAAC;MACDH,MAAM,EAAE/B;IACV,CAAC,CACF;IACDc,YAAY;IACZqB,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;IACxC,IAAInB,MAAM,GAAGA,MAAM,CAACoB,MAAM,GAAG,CAAC,CAAC,CAAC;IAChC,GAAGrB,IAAI;IACPsB,QAAQ,EAAE;MACR,GAAGjB,eAAe;MAClB,IAAIJ,MAAM,GAAGA,MAAM,CAACoB,MAAM,CAACC,QAAQ,GAAG,CAAC,CAAC,CAAC;MACzC,GAAGtB,IAAI,CAACsB;IACV;EACF,CAAC;EAEDlC,KAAK,CAACmC,GAAG,CAAC9B,SAAS,EAAEmB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB"}
@@ -155,7 +155,7 @@ function getBuilderForIdentifier(definedProcessor, path, imports, options) {
155
155
  }
156
156
  const replacer = (replacement, isPure) => {
157
157
  mutate(prev, p => {
158
- p.replaceWith(replacement);
158
+ p.replaceWith(typeof replacement === 'function' ? replacement(p) : replacement);
159
159
  if (isPure) {
160
160
  p.addComment('leading', '#__PURE__');
161
161
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getTagProcessor.js","names":["readFileSync","basename","dirname","join","types","t","addDefault","addNamed","BaseProcessor","findPackageJSON","collectExportsAndImports","explicitImport","collectTemplateDependencies","extractExpression","getSource","isNotNull","mutate","getTraversalCache","last","arr","length","zip","arr1","arr2","result","i","push","buildCodeFrameError","path","message","Error","definedTagsCache","Map","getDefinedTagsFromPackage","pkgName","filename","has","get","packageJSONPath","undefined","packageDir","packageJSON","JSON","parse","definedTags","tags","normalizedTags","Object","entries","reduce","acc","key","value","startsWith","require","resolve","paths","set","isValidProcessorClass","module","constructor","getProcessorFromPackage","packageName","tagName","processorPath","Processor","default","getProcessorFromFile","getProcessorForImport","imported","source","options","tagResolver","customFile","processor","getBuilderForIdentifier","definedProcessor","imports","tagSource","tagPath","parentPath","isMemberExpression","property","node","params","prev","current","isSequenceExpression","expressions","isCallExpression","callee","args","cookedArgs","map","arg","buildError","bind","isExpression","type","extracted","evaluate","filter","object","isIdentifier","computed","name","isStringLiteral","isTaggedTemplateExpression","tag","quasis","expressionValues","replacer","replacement","isPure","p","replaceWith","addComment","importHelpers","addDefaultImport","importedSource","nameHint","addNamedImport","astService","Proxy","target","prop","receiver","Reflect","loc","getDisplayName","idx","displayName","parent","findParent","isObjectProperty","isJSXOpeningElement","isVariableDeclarator","toString","keyPath","isJSXIdentifier","id","test","replace","isTagReferenced","isReferenced","referencePaths","scope","getBinding","counters","WeakMap","getNextIndex","state","counter","getDefinedProcessors","cache","defined","forEach","local","createProcessorInstance","fileContext","builder","e","SKIP","applyProcessors","callback","definedProcessors","usages","idName","includes","split","objBinding","identifier","sort","a","b","start","usage","instance"],"sources":["../../src/utils/getTagProcessor.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { basename, dirname, join } from 'path';\n\nimport { types as t } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport type { NodePath } from '@babel/traverse';\nimport type {\n Expression,\n Identifier,\n MemberExpression,\n Program,\n SourceLocation,\n} from '@babel/types';\n\nimport { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Param,\n Params,\n IFileContext,\n TagSource,\n} from '@wyw-in-js/processor-utils';\nimport { findPackageJSON } from '@wyw-in-js/shared';\nimport type { ExpressionValue, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { IImport } from './collectExportsAndImports';\nimport {\n collectExportsAndImports,\n explicitImport,\n} from './collectExportsAndImports';\nimport {\n collectTemplateDependencies,\n extractExpression,\n} from './collectTemplateDependencies';\nimport { getSource } from './getSource';\nimport { isNotNull } from './isNotNull';\nimport { mutate } from './scopeHelpers';\nimport { getTraversalCache } from './traversalCache';\n\ntype BuilderArgs = ConstructorParameters<typeof BaseProcessor> extends [\n Params,\n TagSource,\n typeof t,\n SourceLocation | null,\n (replacement: Expression, isPure: boolean) => void,\n ...infer T,\n]\n ? T\n : never;\n\ntype Builder = (...args: BuilderArgs) => BaseProcessor;\n\ntype DefinedProcessor = [ProcessorClass, TagSource];\ntype DefinedProcessors = Map<string, DefinedProcessor>;\n\nexport type ProcessorClass = new (\n ...args: ConstructorParameters<typeof BaseProcessor>\n) => BaseProcessor;\n\nconst last = <T>(arr: T[]): T | undefined => arr[arr.length - 1];\n\nfunction zip<T1, T2>(arr1: T1[], arr2: T2[]) {\n const result: (T1 | T2)[] = [];\n for (let i = 0; i < arr1.length; i++) {\n result.push(arr1[i]);\n if (arr2[i]) result.push(arr2[i]);\n }\n\n return result;\n}\n\nfunction buildCodeFrameError(path: NodePath, message: string): Error {\n try {\n return path.buildCodeFrameError(message);\n } catch {\n return new Error(message);\n }\n}\n\nconst definedTagsCache = new Map<string, Record<string, string> | undefined>();\nconst getDefinedTagsFromPackage = (\n pkgName: string,\n filename: string | null | undefined\n): Record<string, string> | undefined => {\n if (definedTagsCache.has(pkgName)) {\n return definedTagsCache.get(pkgName);\n }\n\n const packageJSONPath = findPackageJSON(pkgName, filename);\n if (!packageJSONPath) {\n return undefined;\n }\n\n const packageDir = dirname(packageJSONPath);\n const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'));\n const definedTags: Record<string, string> | undefined =\n packageJSON['wyw-in-js']?.tags;\n\n const normalizedTags = definedTags\n ? Object.entries(definedTags).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: value.startsWith('.')\n ? join(packageDir, value)\n : require.resolve(value, { paths: [packageDir] }),\n }),\n {} as Record<string, string>\n )\n : undefined;\n\n definedTagsCache.set(pkgName, normalizedTags);\n\n return normalizedTags;\n};\n\nfunction isValidProcessorClass(module: unknown): module is ProcessorClass {\n return module instanceof BaseProcessor.constructor;\n}\n\nfunction getProcessorFromPackage(\n packageName: string,\n tagName: string,\n filename: string | null | undefined\n): ProcessorClass | null {\n const definedTags = getDefinedTagsFromPackage(packageName, filename);\n const processorPath = definedTags?.[tagName];\n if (!processorPath) {\n return null;\n }\n\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nfunction getProcessorFromFile(processorPath: string): ProcessorClass | null {\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nexport function getProcessorForImport(\n { imported, source }: IImport,\n filename: string | null | undefined,\n options: Pick<StrictOptions, 'tagResolver'>\n): [ProcessorClass | null, TagSource] {\n const tagResolver = options.tagResolver ?? (() => null);\n\n const customFile = tagResolver(source, imported);\n const processor = customFile\n ? getProcessorFromFile(customFile)\n : getProcessorFromPackage(source, imported, filename);\n return [processor, { imported, source }];\n}\n\nfunction getBuilderForIdentifier(\n definedProcessor: DefinedProcessor,\n path: NodePath<Identifier>,\n imports: IImport[],\n options: Pick<StrictOptions, 'evaluate'>\n): Builder | null {\n const [Processor, tagSource] = definedProcessor;\n let tagPath: NodePath<Identifier | MemberExpression> = path;\n if (tagPath.parentPath?.isMemberExpression({ property: tagPath.node })) {\n tagPath = tagPath.parentPath;\n }\n\n if (!Processor || !tagSource || !tagPath) {\n return null;\n }\n\n const params: Param[] = [['callee', tagPath.node]];\n let prev: NodePath = tagPath;\n let current: NodePath | null = tagPath.parentPath;\n while (current && current !== path) {\n if (\n current?.isSequenceExpression() &&\n last(current.node.expressions) === prev.node\n ) {\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isCallExpression({ callee: prev.node })) {\n const args = current.get('arguments');\n const cookedArgs = args\n .map((arg) => {\n const buildError = arg.buildCodeFrameError.bind(arg);\n if (!arg.isExpression()) {\n throw buildError(`Unexpected type of an argument ${arg.type}`);\n }\n const source = getSource(arg);\n const extracted = extractExpression(arg, options.evaluate, imports);\n return {\n ...extracted,\n source,\n buildCodeFrameError: buildError,\n } as ExpressionValue;\n })\n .filter(isNotNull);\n\n params.push(['call', ...cookedArgs]);\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isMemberExpression({ object: prev.node })) {\n const property = current.get('property');\n if (property.isIdentifier() && !current.node.computed) {\n params.push(['member', property.node.name]);\n } else if (property.isStringLiteral()) {\n params.push(['member', property.node.value]);\n } else {\n throw property.buildCodeFrameError(`Unexpected type of a property`);\n }\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isTaggedTemplateExpression({ tag: prev.node })) {\n const [quasis, expressionValues] = collectTemplateDependencies(\n current,\n options.evaluate\n );\n params.push(['template', zip(quasis, expressionValues)]);\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n break;\n }\n\n const replacer = (replacement: Expression, isPure: boolean) => {\n mutate(prev, (p) => {\n p.replaceWith(replacement);\n if (isPure) {\n p.addComment('leading', '#__PURE__');\n }\n });\n };\n\n const importHelpers = {\n addDefaultImport: (importedSource: string, nameHint?: string) =>\n addDefault(path, importedSource, { nameHint }),\n addNamedImport: (\n name: string,\n importedSource: string,\n nameHint: string = name\n ) => addNamed(path, name, importedSource, { nameHint }),\n };\n\n type AstService = typeof t & typeof importHelpers;\n\n const astService = new Proxy<AstService>(t as AstService, {\n get(target, prop, receiver) {\n if (prop in importHelpers) {\n return importHelpers[prop as keyof typeof importHelpers];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n });\n\n return (...args: BuilderArgs) =>\n new Processor(\n params,\n tagSource,\n astService,\n tagPath.node.loc ?? null,\n replacer,\n ...args\n );\n}\n\nfunction getDisplayName(\n path: NodePath<Identifier>,\n idx: number,\n filename?: string | null\n): string {\n let displayName: string | undefined;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isObjectProperty()) {\n if ('name' in parent.node.key) {\n displayName = parent.node.key.name;\n } else if ('value' in parent.node.key) {\n displayName = parent.node.key.value.toString();\n } else {\n const keyPath = parent.get('key');\n displayName = getSource(keyPath);\n }\n } else if (parent.isJSXOpeningElement()) {\n const name = parent.get('name');\n if (name.isJSXIdentifier()) {\n displayName = name.node.name;\n }\n } else if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n if (id.isIdentifier()) {\n displayName = id.node.name;\n }\n }\n }\n\n if (!displayName) {\n // Try to derive the path from the filename\n displayName = basename(filename ?? 'unknown');\n\n if (filename && /^index\\.[a-z\\d]+$/.test(displayName)) {\n // If the file name is 'index', better to get name from parent folder\n displayName = basename(dirname(filename));\n }\n\n // Remove the file extension\n displayName = displayName.replace(/\\.[a-z\\d]+$/, '');\n\n if (displayName) {\n displayName += idx;\n } else {\n throw new Error(\n \"Couldn't determine a name for the component. Ensure that it's either:\\n\" +\n '- Assigned to a variable\\n' +\n '- Is an object property\\n' +\n '- Is a prop in a JSX element\\n'\n );\n }\n }\n\n return displayName;\n}\n\nfunction isTagReferenced(path: NodePath): boolean {\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n let isReferenced = true;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n // FIXME: replace with id.isReferencedIdentifier()\n if (id.isIdentifier()) {\n const { referencePaths } = path.scope.getBinding(id.node.name) || {\n referencePaths: [],\n };\n\n isReferenced = referencePaths.length !== 0;\n }\n }\n }\n\n return isReferenced;\n}\n\nconst counters = new WeakMap<IFileContext, number>();\nconst getNextIndex = (state: IFileContext) => {\n const counter = counters.get(state) ?? 0;\n counters.set(state, counter + 1);\n return counter;\n};\n\nexport function getDefinedProcessors(\n imports: IImport[],\n path: NodePath<Program>,\n filename: string | null | undefined,\n options: Pick<StrictOptions, 'tagResolver'>\n): DefinedProcessors {\n const cache = getTraversalCache<DefinedProcessors, NodePath<Program>>(\n path,\n 'getDefinedProcessors'\n );\n\n if (!cache.has(path)) {\n const defined: DefinedProcessors = new Map();\n\n imports.forEach((i) => {\n const [processor, tagSource] = getProcessorForImport(\n i,\n filename,\n options\n );\n const { local } = i;\n if (!processor) {\n return;\n }\n\n let name: string | null = null;\n if (local.isIdentifier()) {\n name = local.node.name;\n }\n\n if (name === null && local.isMemberExpression()) {\n const property = local.get('property');\n const object = local.get('object');\n if (property.isIdentifier() && object.isIdentifier()) {\n name = `${object.node.name}.${property.node.name}`;\n }\n }\n\n if (name === null) {\n return;\n }\n\n defined.set(name, [processor, tagSource]);\n });\n\n cache.set(path, defined);\n }\n\n return cache.get(path)!;\n}\n\nfunction createProcessorInstance(\n definedProcessor: [ProcessorClass, TagSource],\n imports: IImport[],\n path: NodePath<Identifier>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >\n): BaseProcessor | null {\n const cache = getTraversalCache<BaseProcessor | null, Identifier>(\n path,\n 'createProcessorInstance'\n );\n\n if (!cache.has(path.node)) {\n try {\n const builder = getBuilderForIdentifier(\n definedProcessor,\n path,\n imports,\n options\n );\n if (builder) {\n // Increment the index of the style we're processing\n // This is used for slug generation to prevent collision\n // Also used for display name if it couldn't be determined\n const idx = getNextIndex(fileContext);\n\n const displayName = getDisplayName(path, idx, fileContext.filename);\n\n const processor = builder(\n displayName,\n isTagReferenced(path),\n idx,\n options,\n fileContext\n );\n\n cache.set(path.node, processor);\n } else {\n cache.set(path.node, null);\n }\n } catch (e) {\n if (e === BaseProcessor.SKIP) {\n cache.set(path.node, null);\n return null;\n }\n\n if (e instanceof Error) {\n throw buildCodeFrameError(path, e.message);\n }\n\n throw e;\n }\n }\n\n return cache.get(path.node) ?? null;\n}\n\nexport function applyProcessors(\n path: NodePath<Program>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >,\n callback: (processor: BaseProcessor) => void\n) {\n const imports = collectExportsAndImports(path).imports.filter(explicitImport);\n\n const definedProcessors = getDefinedProcessors(\n imports,\n path,\n fileContext.filename,\n options\n );\n\n const usages: {\n identifier: NodePath<Identifier>;\n processor: DefinedProcessor;\n }[] = [];\n\n definedProcessors.forEach((processor, idName) => {\n if (idName.includes('.')) {\n // It's a member expression\n const [object, property] = idName.split('.');\n const objBinding = path.scope.getBinding(object);\n if (!objBinding) {\n return;\n }\n\n objBinding.referencePaths.forEach((p) => {\n const parent = p.parentPath;\n if (!parent?.isMemberExpression()) {\n return;\n }\n\n const identifier = parent.get('property');\n if (identifier.isIdentifier({ name: property })) {\n usages.push({\n identifier,\n processor,\n });\n }\n });\n\n return;\n }\n\n path.scope.getBinding(idName)?.referencePaths.forEach((identifier) => {\n if (identifier.isIdentifier()) {\n usages.push({\n identifier,\n processor,\n });\n }\n });\n });\n\n // The same order, the same slugs\n usages.sort(\n (a, b) => (a.identifier.node.start ?? 0) - (b.identifier.node.start ?? 0)\n );\n\n usages.forEach((usage) => {\n const definedProcessor = usage.processor;\n\n if (!definedProcessor) {\n return;\n }\n\n const instance = createProcessorInstance(\n definedProcessor,\n imports,\n usage.identifier,\n fileContext,\n options\n );\n\n if (instance === null) {\n return;\n }\n\n callback(instance);\n });\n}\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,IAAI;AACjC,SAASC,QAAQ,EAAEC,OAAO,EAAEC,IAAI,QAAQ,MAAM;AAE9C,SAASC,KAAK,IAAIC,CAAC,QAAQ,aAAa;AACxC,SAASC,UAAU,EAAEC,QAAQ,QAAQ,8BAA8B;AAUnE,SAASC,aAAa,QAAQ,4BAA4B;AAO1D,SAASC,eAAe,QAAQ,mBAAmB;AAInD,SACEC,wBAAwB,EACxBC,cAAc,QACT,4BAA4B;AACnC,SACEC,2BAA2B,EAC3BC,iBAAiB,QACZ,+BAA+B;AACtC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,iBAAiB,QAAQ,kBAAkB;AAsBpD,MAAMC,IAAI,GAAOC,GAAQ,IAAoBA,GAAG,CAACA,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC;AAEhE,SAASC,GAAGA,CAASC,IAAU,EAAEC,IAAU,EAAE;EAC3C,MAAMC,MAAmB,GAAG,EAAE;EAC9B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACF,MAAM,EAAEK,CAAC,EAAE,EAAE;IACpCD,MAAM,CAACE,IAAI,CAACJ,IAAI,CAACG,CAAC,CAAC,CAAC;IACpB,IAAIF,IAAI,CAACE,CAAC,CAAC,EAAED,MAAM,CAACE,IAAI,CAACH,IAAI,CAACE,CAAC,CAAC,CAAC;EACnC;EAEA,OAAOD,MAAM;AACf;AAEA,SAASG,mBAAmBA,CAACC,IAAc,EAAEC,OAAe,EAAS;EACnE,IAAI;IACF,OAAOD,IAAI,CAAC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AgB,EAChBC,OAAO,EACPmG,KAAK,CAACL,UAAU,EAChBZ,WAAW,EACXxF,OACF,CAAC;IAED,IAAI0G,QAAQ,KAAK,IAAI,EAAE;MACrB;IACF;IAEAb,QAAQ,CAACa,QAAQ,CAAC;EACpB,CAAC,CAAC;AACJ"}
1
+ {"version":3,"file":"getTagProcessor.js","names":["readFileSync","basename","dirname","join","types","t","addDefault","addNamed","BaseProcessor","findPackageJSON","collectExportsAndImports","explicitImport","collectTemplateDependencies","extractExpression","getSource","isNotNull","mutate","getTraversalCache","last","arr","length","zip","arr1","arr2","result","i","push","buildCodeFrameError","path","message","Error","definedTagsCache","Map","getDefinedTagsFromPackage","pkgName","filename","has","get","packageJSONPath","undefined","packageDir","packageJSON","JSON","parse","definedTags","tags","normalizedTags","Object","entries","reduce","acc","key","value","startsWith","require","resolve","paths","set","isValidProcessorClass","module","constructor","getProcessorFromPackage","packageName","tagName","processorPath","Processor","default","getProcessorFromFile","getProcessorForImport","imported","source","options","tagResolver","customFile","processor","getBuilderForIdentifier","definedProcessor","imports","tagSource","tagPath","parentPath","isMemberExpression","property","node","params","prev","current","isSequenceExpression","expressions","isCallExpression","callee","args","cookedArgs","map","arg","buildError","bind","isExpression","type","extracted","evaluate","filter","object","isIdentifier","computed","name","isStringLiteral","isTaggedTemplateExpression","tag","quasis","expressionValues","replacer","replacement","isPure","p","replaceWith","addComment","importHelpers","addDefaultImport","importedSource","nameHint","addNamedImport","astService","Proxy","target","prop","receiver","Reflect","loc","getDisplayName","idx","displayName","parent","findParent","isObjectProperty","isJSXOpeningElement","isVariableDeclarator","toString","keyPath","isJSXIdentifier","id","test","replace","isTagReferenced","isReferenced","referencePaths","scope","getBinding","counters","WeakMap","getNextIndex","state","counter","getDefinedProcessors","cache","defined","forEach","local","createProcessorInstance","fileContext","builder","e","SKIP","applyProcessors","callback","definedProcessors","usages","idName","includes","split","objBinding","identifier","sort","a","b","start","usage","instance"],"sources":["../../src/utils/getTagProcessor.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { basename, dirname, join } from 'path';\n\nimport { types as t } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport type { NodePath } from '@babel/traverse';\nimport type {\n Expression,\n Identifier,\n MemberExpression,\n Program,\n SourceLocation,\n} from '@babel/types';\n\nimport { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Param,\n Params,\n IFileContext,\n TagSource,\n} from '@wyw-in-js/processor-utils';\nimport { findPackageJSON } from '@wyw-in-js/shared';\nimport type { ExpressionValue, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { IImport } from './collectExportsAndImports';\nimport {\n collectExportsAndImports,\n explicitImport,\n} from './collectExportsAndImports';\nimport {\n collectTemplateDependencies,\n extractExpression,\n} from './collectTemplateDependencies';\nimport { getSource } from './getSource';\nimport { isNotNull } from './isNotNull';\nimport { mutate } from './scopeHelpers';\nimport { getTraversalCache } from './traversalCache';\n\ntype BuilderArgs = ConstructorParameters<typeof BaseProcessor> extends [\n Params,\n TagSource,\n typeof t,\n SourceLocation | null,\n (replacement: Expression, isPure: boolean) => void,\n ...infer T,\n]\n ? T\n : never;\n\ntype Builder = (...args: BuilderArgs) => BaseProcessor;\n\ntype DefinedProcessor = [ProcessorClass, TagSource];\ntype DefinedProcessors = Map<string, DefinedProcessor>;\n\nexport type ProcessorClass = new (\n ...args: ConstructorParameters<typeof BaseProcessor>\n) => BaseProcessor;\n\nconst last = <T>(arr: T[]): T | undefined => arr[arr.length - 1];\n\nfunction zip<T1, T2>(arr1: T1[], arr2: T2[]) {\n const result: (T1 | T2)[] = [];\n for (let i = 0; i < arr1.length; i++) {\n result.push(arr1[i]);\n if (arr2[i]) result.push(arr2[i]);\n }\n\n return result;\n}\n\nfunction buildCodeFrameError(path: NodePath, message: string): Error {\n try {\n return path.buildCodeFrameError(message);\n } catch {\n return new Error(message);\n }\n}\n\nconst definedTagsCache = new Map<string, Record<string, string> | undefined>();\nconst getDefinedTagsFromPackage = (\n pkgName: string,\n filename: string | null | undefined\n): Record<string, string> | undefined => {\n if (definedTagsCache.has(pkgName)) {\n return definedTagsCache.get(pkgName);\n }\n\n const packageJSONPath = findPackageJSON(pkgName, filename);\n if (!packageJSONPath) {\n return undefined;\n }\n\n const packageDir = dirname(packageJSONPath);\n const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'));\n const definedTags: Record<string, string> | undefined =\n packageJSON['wyw-in-js']?.tags;\n\n const normalizedTags = definedTags\n ? Object.entries(definedTags).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: value.startsWith('.')\n ? join(packageDir, value)\n : require.resolve(value, { paths: [packageDir] }),\n }),\n {} as Record<string, string>\n )\n : undefined;\n\n definedTagsCache.set(pkgName, normalizedTags);\n\n return normalizedTags;\n};\n\nfunction isValidProcessorClass(module: unknown): module is ProcessorClass {\n return module instanceof BaseProcessor.constructor;\n}\n\nfunction getProcessorFromPackage(\n packageName: string,\n tagName: string,\n filename: string | null | undefined\n): ProcessorClass | null {\n const definedTags = getDefinedTagsFromPackage(packageName, filename);\n const processorPath = definedTags?.[tagName];\n if (!processorPath) {\n return null;\n }\n\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nfunction getProcessorFromFile(processorPath: string): ProcessorClass | null {\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nexport function getProcessorForImport(\n { imported, source }: IImport,\n filename: string | null | undefined,\n options: Pick<StrictOptions, 'tagResolver'>\n): [ProcessorClass | null, TagSource] {\n const tagResolver = options.tagResolver ?? (() => null);\n\n const customFile = tagResolver(source, imported);\n const processor = customFile\n ? getProcessorFromFile(customFile)\n : getProcessorFromPackage(source, imported, filename);\n return [processor, { imported, source }];\n}\n\nfunction getBuilderForIdentifier(\n definedProcessor: DefinedProcessor,\n path: NodePath<Identifier>,\n imports: IImport[],\n options: Pick<StrictOptions, 'evaluate'>\n): Builder | null {\n const [Processor, tagSource] = definedProcessor;\n let tagPath: NodePath<Identifier | MemberExpression> = path;\n if (tagPath.parentPath?.isMemberExpression({ property: tagPath.node })) {\n tagPath = tagPath.parentPath;\n }\n\n if (!Processor || !tagSource || !tagPath) {\n return null;\n }\n\n const params: Param[] = [['callee', tagPath.node]];\n let prev: NodePath = tagPath;\n let current: NodePath | null = tagPath.parentPath;\n while (current && current !== path) {\n if (\n current?.isSequenceExpression() &&\n last(current.node.expressions) === prev.node\n ) {\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isCallExpression({ callee: prev.node })) {\n const args = current.get('arguments');\n const cookedArgs = args\n .map((arg) => {\n const buildError = arg.buildCodeFrameError.bind(arg);\n if (!arg.isExpression()) {\n throw buildError(`Unexpected type of an argument ${arg.type}`);\n }\n const source = getSource(arg);\n const extracted = extractExpression(arg, options.evaluate, imports);\n return {\n ...extracted,\n source,\n buildCodeFrameError: buildError,\n } as ExpressionValue;\n })\n .filter(isNotNull);\n\n params.push(['call', ...cookedArgs]);\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isMemberExpression({ object: prev.node })) {\n const property = current.get('property');\n if (property.isIdentifier() && !current.node.computed) {\n params.push(['member', property.node.name]);\n } else if (property.isStringLiteral()) {\n params.push(['member', property.node.value]);\n } else {\n throw property.buildCodeFrameError(`Unexpected type of a property`);\n }\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isTaggedTemplateExpression({ tag: prev.node })) {\n const [quasis, expressionValues] = collectTemplateDependencies(\n current,\n options.evaluate\n );\n params.push(['template', zip(quasis, expressionValues)]);\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n break;\n }\n\n const replacer = (\n replacement: Expression | ((tagPath: NodePath) => Expression),\n isPure: boolean\n ) => {\n mutate(prev, (p) => {\n p.replaceWith(\n typeof replacement === 'function' ? replacement(p) : replacement\n );\n if (isPure) {\n p.addComment('leading', '#__PURE__');\n }\n });\n };\n\n const importHelpers = {\n addDefaultImport: (importedSource: string, nameHint?: string) =>\n addDefault(path, importedSource, { nameHint }),\n addNamedImport: (\n name: string,\n importedSource: string,\n nameHint: string = name\n ) => addNamed(path, name, importedSource, { nameHint }),\n };\n\n type AstService = typeof t & typeof importHelpers;\n\n const astService = new Proxy<AstService>(t as AstService, {\n get(target, prop, receiver) {\n if (prop in importHelpers) {\n return importHelpers[prop as keyof typeof importHelpers];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n });\n\n return (...args: BuilderArgs) =>\n new Processor(\n params,\n tagSource,\n astService,\n tagPath.node.loc ?? null,\n replacer,\n ...args\n );\n}\n\nfunction getDisplayName(\n path: NodePath<Identifier>,\n idx: number,\n filename?: string | null\n): string {\n let displayName: string | undefined;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isObjectProperty()) {\n if ('name' in parent.node.key) {\n displayName = parent.node.key.name;\n } else if ('value' in parent.node.key) {\n displayName = parent.node.key.value.toString();\n } else {\n const keyPath = parent.get('key');\n displayName = getSource(keyPath);\n }\n } else if (parent.isJSXOpeningElement()) {\n const name = parent.get('name');\n if (name.isJSXIdentifier()) {\n displayName = name.node.name;\n }\n } else if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n if (id.isIdentifier()) {\n displayName = id.node.name;\n }\n }\n }\n\n if (!displayName) {\n // Try to derive the path from the filename\n displayName = basename(filename ?? 'unknown');\n\n if (filename && /^index\\.[a-z\\d]+$/.test(displayName)) {\n // If the file name is 'index', better to get name from parent folder\n displayName = basename(dirname(filename));\n }\n\n // Remove the file extension\n displayName = displayName.replace(/\\.[a-z\\d]+$/, '');\n\n if (displayName) {\n displayName += idx;\n } else {\n throw new Error(\n \"Couldn't determine a name for the component. Ensure that it's either:\\n\" +\n '- Assigned to a variable\\n' +\n '- Is an object property\\n' +\n '- Is a prop in a JSX element\\n'\n );\n }\n }\n\n return displayName;\n}\n\nfunction isTagReferenced(path: NodePath): boolean {\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n let isReferenced = true;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n // FIXME: replace with id.isReferencedIdentifier()\n if (id.isIdentifier()) {\n const { referencePaths } = path.scope.getBinding(id.node.name) || {\n referencePaths: [],\n };\n\n isReferenced = referencePaths.length !== 0;\n }\n }\n }\n\n return isReferenced;\n}\n\nconst counters = new WeakMap<IFileContext, number>();\nconst getNextIndex = (state: IFileContext) => {\n const counter = counters.get(state) ?? 0;\n counters.set(state, counter + 1);\n return counter;\n};\n\nexport function getDefinedProcessors(\n imports: IImport[],\n path: NodePath<Program>,\n filename: string | null | undefined,\n options: Pick<StrictOptions, 'tagResolver'>\n): DefinedProcessors {\n const cache = getTraversalCache<DefinedProcessors, NodePath<Program>>(\n path,\n 'getDefinedProcessors'\n );\n\n if (!cache.has(path)) {\n const defined: DefinedProcessors = new Map();\n\n imports.forEach((i) => {\n const [processor, tagSource] = getProcessorForImport(\n i,\n filename,\n options\n );\n const { local } = i;\n if (!processor) {\n return;\n }\n\n let name: string | null = null;\n if (local.isIdentifier()) {\n name = local.node.name;\n }\n\n if (name === null && local.isMemberExpression()) {\n const property = local.get('property');\n const object = local.get('object');\n if (property.isIdentifier() && object.isIdentifier()) {\n name = `${object.node.name}.${property.node.name}`;\n }\n }\n\n if (name === null) {\n return;\n }\n\n defined.set(name, [processor, tagSource]);\n });\n\n cache.set(path, defined);\n }\n\n return cache.get(path)!;\n}\n\nfunction createProcessorInstance(\n definedProcessor: [ProcessorClass, TagSource],\n imports: IImport[],\n path: NodePath<Identifier>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >\n): BaseProcessor | null {\n const cache = getTraversalCache<BaseProcessor | null, Identifier>(\n path,\n 'createProcessorInstance'\n );\n\n if (!cache.has(path.node)) {\n try {\n const builder = getBuilderForIdentifier(\n definedProcessor,\n path,\n imports,\n options\n );\n if (builder) {\n // Increment the index of the style we're processing\n // This is used for slug generation to prevent collision\n // Also used for display name if it couldn't be determined\n const idx = getNextIndex(fileContext);\n\n const displayName = getDisplayName(path, idx, fileContext.filename);\n\n const processor = builder(\n displayName,\n isTagReferenced(path),\n idx,\n options,\n fileContext\n );\n\n cache.set(path.node, processor);\n } else {\n cache.set(path.node, null);\n }\n } catch (e) {\n if (e === BaseProcessor.SKIP) {\n cache.set(path.node, null);\n return null;\n }\n\n if (e instanceof Error) {\n throw buildCodeFrameError(path, e.message);\n }\n\n throw e;\n }\n }\n\n return cache.get(path.node) ?? null;\n}\n\nexport function applyProcessors(\n path: NodePath<Program>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >,\n callback: (processor: BaseProcessor) => void\n) {\n const imports = collectExportsAndImports(path).imports.filter(explicitImport);\n\n const definedProcessors = getDefinedProcessors(\n imports,\n path,\n fileContext.filename,\n options\n );\n\n const usages: {\n identifier: NodePath<Identifier>;\n processor: DefinedProcessor;\n }[] = [];\n\n definedProcessors.forEach((processor, idName) => {\n if (idName.includes('.')) {\n // It's a member expression\n const [object, property] = idName.split('.');\n const objBinding = path.scope.getBinding(object);\n if (!objBinding) {\n return;\n }\n\n objBinding.referencePaths.forEach((p) => {\n const parent = p.parentPath;\n if (!parent?.isMemberExpression()) {\n return;\n }\n\n const identifier = parent.get('property');\n if (identifier.isIdentifier({ name: property })) {\n usages.push({\n identifier,\n processor,\n });\n }\n });\n\n return;\n }\n\n path.scope.getBinding(idName)?.referencePaths.forEach((identifier) => {\n if (identifier.isIdentifier()) {\n usages.push({\n identifier,\n processor,\n });\n }\n });\n });\n\n // The same order, the same slugs\n usages.sort(\n (a, b) => (a.identifier.node.start ?? 0) - (b.identifier.node.start ?? 0)\n );\n\n usages.forEach((usage) => {\n const definedProcessor = usage.processor;\n\n if (!definedProcessor) {\n return;\n }\n\n const instance = createProcessorInstance(\n definedProcessor,\n imports,\n usage.identifier,\n fileContext,\n options\n );\n\n if (instance === null) {\n return;\n }\n\n callback(instance);\n });\n}\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,IAAI;AACjC,SAASC,QAAQ,EAAEC,OAAO,EAAEC,IAAI,QAAQ,MAAM;AAE9C,SAASC,KAAK,IAAIC,CAAC,QAAQ,aAAa;AACxC,SAASC,UAAU,EAAEC,QAAQ,QAAQ,8BAA8B;AAUnE,SAASC,aAAa,QAAQ,4BAA4B;AAO1D,SAASC,eAAe,QAAQ,mBAAmB;AAInD,SACEC,wBAAwB,EACxBC,cAAc,QACT,4BAA4B;AACnC,SACEC,2BAA2B,EAC3BC,iBAAiB,QACZ,+BAA+B;AACtC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,iBAAiB,QAAQ,kBAAkB;AAsBpD,MAAMC,IAAI,GAAOC,GAAQ,IAAoBA,GAAG,CAACA,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC;AAEhE,SAASC,GAAGA,CAASC,IAAU,EAAEC,IAAU,EAAE;EAC3C,MAAMC,MAAmB,GAAG,EAAE;EAC9B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACF,MAAM,EAAEK,CAAC,EAAE,EAAE;IACpCD,MAAM,CAACE,IAAI,CAACJ,IAAI,CAACG,CAAC,CAAC,CAAC;IACpB,IAAIF,IAAI,CAACE,CAAC,CAAC,EAAED,MAAM,CAACE,IAAI,CAACH,IAAI,CAACE,CAAC,CAAC,CAAC;EACnC;EAEA,OAAOD,MAAM;AAC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AAK;IACxB,MAAMpG,gBAAgB,GAAGoG,KAAK,CAACtG,SAAS;IAExC,IAAI,CAACE,gBAAgB,EAAE;MACrB;IACF;IAEA,MAAMqG,QAAQ,GAAGnB,uBAAuB,CACtClF,gBAAgB,EAChBC,OAAO,EACPmG,KAAK,CAACL,UAAU,EAChBZ,WAAW,EACXxF,OACF,CAAC;IAED,IAAI0G,QAAQ,KAAK,IAAI,EAAE;MACrB;IACF;IAEAb,QAAQ,CAACa,QAAQ,CAAC;EACpB,CAAC,CAAC;AACJ"}
package/lib/module.js CHANGED
@@ -9,6 +9,7 @@ var _module = _interopRequireDefault(require("module"));
9
9
  var _path = _interopRequireDefault(require("path"));
10
10
  var _vm = _interopRequireDefault(require("vm"));
11
11
  var _tsInvariant = require("ts-invariant");
12
+ var _shared = require("@wyw-in-js/shared");
12
13
  require("./utils/dispose-polyfill");
13
14
  var _Entrypoint = require("./transform/Entrypoint");
14
15
  var _Entrypoint2 = require("./transform/Entrypoint.helpers");
@@ -127,7 +128,7 @@ class Module {
127
128
  this.services = services;
128
129
  this.moduleImpl = moduleImpl;
129
130
  this.cache = services.cache;
130
- this.#entrypointRef = new WeakRef(entrypoint);
131
+ this.#entrypointRef = (0, _shared.isFeatureEnabled)(services.options.pluginOptions.features, 'useWeakRefInEval', entrypoint.name) ? new WeakRef(entrypoint) : entrypoint;
131
132
  this.idx = entrypoint.idx;
132
133
  this.id = entrypoint.name;
133
134
  this.filename = entrypoint.name;
@@ -151,7 +152,7 @@ class Module {
151
152
  this.debug('the whole exports was overridden with %O', value);
152
153
  }
153
154
  get entrypoint() {
154
- const entrypoint = this.#entrypointRef.deref();
155
+ const entrypoint = this.#entrypointRef instanceof WeakRef ? this.#entrypointRef.deref() : this.#entrypointRef;
155
156
  (0, _tsInvariant.invariant)(entrypoint, `Module ${this.idx} is disposed`);
156
157
  return entrypoint;
157
158
  }
package/lib/module.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","names":["_fs","_interopRequireDefault","require","_module","_path","_vm","_tsInvariant","_Entrypoint","_Entrypoint2","_UnprocessedEntrypointError","_createVmContext","obj","__esModule","default","DefaultModuleImplementation","exports","NativeModule","builtins","assert","buffer","child_process","cluster","console","constants","crypto","dgram","dns","domain","events","fs","http","https","module","net","os","path","punycode","process","querystring","readline","repl","stream","string_decoder","sys","timers","tls","tty","url","util","vm","zlib","NOOP","getUncached","cached","test","cachedSet","Set","split","has","filter","t","resolve","id","resolved","resolveDependency","invariant","Module","callstack","isEvaluated","Object","assign","debug","dependency","isAbsolute","Error","source","dependencies","push","entrypoint","getEntrypoint","only","evaluated","isSuperSet","evaluatedOnly","m","createChild","evaluate","ensure","bind","entrypointRef","constructor","services","parentModule","moduleImpl","_parentModule$ignored","_entrypoint$ignored","cache","WeakRef","idx","name","filename","log","extend","parentIsIgnored","ignored","extensions","options","pluginOptions","value","deref","assertTransformed","get","evaluatedCreated","supersededWith","add","createEvaluated","transformedCode","JSON","parse","context","teardown","createVmContext","features","__wyw_dynamic_import","__dirname","dirname","overrideContext","script","Script","runInContext","e","isUnprocessedEntrypointError","EvalError","message","join","_entrypoint$evaluated","extension","extname","includes","newEntrypoint","readFileSync","stack","getStack","_entrypoint$only","uncachedExports","length","code","Entrypoint","createRoot","getDependency","Promise","_extensions","added","forEach","ext","_resolveFilename","paths","_nodeModulePaths"],"sources":["../src/module.ts"],"sourcesContent":["/**\n * This is a custom implementation for the module system for evaluating code,\n * used for resolving values for dependencies interpolated in `css` or `styled`.\n *\n * This serves 2 purposes:\n * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`\n * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds\n *\n * We also use it to transpile the code with Babel by default.\n * We also store source maps for it to provide correct error stacktraces.\n *\n */\n\nimport fs from 'fs';\nimport NativeModule from 'module';\nimport path from 'path';\nimport vm from 'vm';\n\nimport { invariant } from 'ts-invariant';\n\nimport type { Debugger } from '@wyw-in-js/shared';\n\nimport './utils/dispose-polyfill';\nimport type { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport { getStack, isSuperSet } from './transform/Entrypoint.helpers';\nimport type { IEntrypointDependency } from './transform/Entrypoint.types';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';\nimport type { Services } from './transform/types';\nimport { createVmContext } from './vm/createVmContext';\n\ntype HiddenModuleMembers = {\n _extensions: Record<string, () => void>;\n _resolveFilename: (\n id: string,\n options: { filename: string; id: string; paths: string[] }\n ) => string;\n _nodeModulePaths(filename: string): string[];\n};\n\nexport const DefaultModuleImplementation = NativeModule as typeof NativeModule &\n HiddenModuleMembers;\n\n// Supported node builtins based on the modules polyfilled by webpack\n// `true` means module is polyfilled, `false` means module is empty\nconst builtins = {\n assert: true,\n buffer: true,\n child_process: false,\n cluster: false,\n console: true,\n constants: true,\n crypto: true,\n dgram: false,\n dns: false,\n domain: true,\n events: true,\n fs: false,\n http: true,\n https: true,\n module: false,\n net: false,\n os: true,\n path: true,\n punycode: true,\n process: true,\n querystring: true,\n readline: false,\n repl: false,\n stream: true,\n string_decoder: true,\n sys: true,\n timers: true,\n tls: false,\n tty: true,\n url: true,\n util: true,\n vm: true,\n zlib: true,\n};\n\nconst NOOP = () => {};\n\nfunction getUncached(cached: string | string[], test: string[]): string[] {\n const cachedSet = new Set(\n typeof cached === 'string' ? cached.split(',') : cached\n );\n\n if (cachedSet.has('*')) {\n return [];\n }\n\n return test.filter((t) => !cachedSet.has(t));\n}\n\nfunction resolve(\n this: { resolveDependency: (id: string) => IEntrypointDependency },\n id: string\n): string {\n const { resolved } = this.resolveDependency(id);\n invariant(resolved, `Unable to resolve \"${id}\"`);\n return resolved;\n}\n\nexport class Module {\n public readonly callstack: string[] = [];\n\n public readonly debug: Debugger;\n\n public readonly dependencies: string[];\n\n public readonly extensions: string[];\n\n public readonly filename: string;\n\n public id: string;\n\n public readonly idx: string;\n\n public readonly ignored: boolean;\n\n public isEvaluated: boolean = false;\n\n public readonly parentIsIgnored: boolean;\n\n public require: {\n (id: string): unknown;\n ensure: () => void;\n resolve: (id: string) => string;\n } = Object.assign(\n (id: string) => {\n if (id in builtins) {\n // The module is in the allowed list of builtin node modules\n // Ideally we should prevent importing them, but webpack polyfills some\n // So we check for the list of polyfills to determine which ones to support\n if (builtins[id as keyof typeof builtins]) {\n this.debug('require', `builtin '${id}'`);\n return require(id);\n }\n\n return null;\n }\n\n // Resolve module id (and filename) relatively to parent module\n const dependency = this.resolveDependency(id);\n if (dependency.resolved === id && !path.isAbsolute(id)) {\n // The module is a builtin node modules, but not in the allowed list\n throw new Error(\n `Unable to import \"${id}\". Importing Node builtins is not supported in the sandbox.`\n );\n }\n\n invariant(\n dependency.resolved,\n `Dependency ${dependency.source} cannot be resolved`\n );\n\n this.dependencies.push(id);\n\n this.debug('require', `${id} -> ${dependency.resolved}`);\n\n const entrypoint = this.getEntrypoint(\n dependency.resolved,\n dependency.only,\n this.debug\n );\n\n if (entrypoint === null) {\n return dependency.resolved;\n }\n\n if (\n entrypoint.evaluated ||\n isSuperSet(entrypoint.evaluatedOnly, dependency.only)\n ) {\n return entrypoint.exports;\n }\n\n const m = this.createChild(entrypoint);\n m.evaluate();\n\n return entrypoint.exports;\n },\n {\n ensure: NOOP,\n resolve: resolve.bind(this),\n }\n );\n\n public resolve = resolve.bind(this);\n\n private cache: TransformCacheCollection;\n\n #entrypointRef: WeakRef<Entrypoint>;\n\n constructor(\n private services: Services,\n entrypoint: Entrypoint,\n parentModule?: Module,\n private moduleImpl: HiddenModuleMembers = DefaultModuleImplementation\n ) {\n this.cache = services.cache;\n this.#entrypointRef = new WeakRef(entrypoint);\n this.idx = entrypoint.idx;\n this.id = entrypoint.name;\n this.filename = entrypoint.name;\n this.dependencies = [];\n this.debug = entrypoint.log.extend('module');\n this.parentIsIgnored = parentModule?.ignored ?? false;\n this.ignored = entrypoint.ignored ?? this.parentIsIgnored;\n\n if (parentModule) {\n this.callstack = [entrypoint.name, ...parentModule.callstack];\n } else {\n this.callstack = [entrypoint.name];\n }\n\n this.extensions = services.options.pluginOptions.extensions;\n\n this.debug('init', entrypoint.name);\n }\n\n public get exports() {\n return this.entrypoint.exports;\n }\n\n public set exports(value) {\n this.entrypoint.exports = value;\n\n this.debug('the whole exports was overridden with %O', value);\n }\n\n protected get entrypoint(): Entrypoint {\n const entrypoint = this.#entrypointRef.deref();\n invariant(entrypoint, `Module ${this.idx} is disposed`);\n return entrypoint;\n }\n\n evaluate(): void {\n const { entrypoint } = this;\n entrypoint.assertTransformed();\n\n const cached = this.cache.get('entrypoints', entrypoint.name)!;\n let evaluatedCreated = false;\n if (!entrypoint.supersededWith) {\n this.cache.add(\n 'entrypoints',\n entrypoint.name,\n entrypoint.createEvaluated()\n );\n evaluatedCreated = true;\n }\n\n const { transformedCode: source } = entrypoint;\n const { pluginOptions } = this.services.options;\n\n if (!source) {\n this.debug(`evaluate`, 'there is nothing to evaluate');\n return;\n }\n\n if (this.isEvaluated) {\n this.debug('evaluate', `is already evaluated`);\n return;\n }\n\n this.debug('evaluate');\n this.debug.extend('source')('%s', source);\n\n this.isEvaluated = true;\n\n const { filename } = this;\n\n if (/\\.json$/.test(filename)) {\n // For JSON files, parse it to a JS object similar to Node\n this.exports = JSON.parse(source);\n return;\n }\n\n const { context, teardown } = createVmContext(\n filename,\n pluginOptions.features,\n {\n module: this,\n exports: entrypoint.exports,\n require: this.require,\n __wyw_dynamic_import: async (id: string) => this.require(id),\n __dirname: path.dirname(filename),\n },\n pluginOptions.overrideContext\n );\n\n try {\n const script = new vm.Script(\n `(function (exports) { ${source}\\n})(exports);`,\n {\n filename,\n }\n );\n\n script.runInContext(context);\n } catch (e) {\n this.isEvaluated = false;\n if (evaluatedCreated) {\n this.cache.add('entrypoints', entrypoint.name, cached);\n }\n\n if (isUnprocessedEntrypointError(e)) {\n // It will be handled by evalFile scenario\n throw e;\n }\n\n if (e instanceof EvalError) {\n this.debug('%O', e);\n\n throw e;\n }\n\n this.debug('%O\\n%O', e, this.callstack);\n throw new EvalError(\n `${(e as Error).message} in${this.callstack.join('\\n| ')}\\n`\n );\n } finally {\n teardown();\n }\n }\n\n getEntrypoint(\n filename: string,\n only: string[],\n log: Debugger\n ): Entrypoint | IEvaluatedEntrypoint | null {\n const extension = path.extname(filename);\n if (extension !== '.json' && !this.extensions.includes(extension)) {\n return null;\n }\n\n const entrypoint = this.cache.get('entrypoints', filename);\n if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {\n log('✅ file has been already evaluated');\n return entrypoint;\n }\n\n if (entrypoint?.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return entrypoint;\n }\n\n if (this.ignored) {\n log(\n '✅ one of the parent files has been ignored during prepare stage. Original code will be used'\n );\n\n const newEntrypoint = this.entrypoint.createChild(\n filename,\n ['*'],\n fs.readFileSync(filename, 'utf-8')\n );\n\n if (newEntrypoint === 'loop') {\n const stack = getStack(this.entrypoint);\n throw new Error(\n `Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`\n );\n }\n\n return newEntrypoint;\n }\n\n // Requested file can be already prepared for evaluation on the stage 1\n if (only && entrypoint) {\n const uncachedExports = getUncached(entrypoint.only ?? [], only);\n if (uncachedExports.length === 0) {\n log('✅ ready for evaluation');\n return entrypoint;\n }\n\n log(\n '❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)',\n uncachedExports,\n entrypoint.only\n );\n } else {\n log('❌ file has not been processed during prepare stage');\n }\n\n // If code wasn't extracted from cache, it indicates that we were unable\n // to process some of the imports on stage1. Let's try to reprocess.\n const code = fs.readFileSync(filename, 'utf-8');\n const newEntrypoint = Entrypoint.createRoot(\n this.services,\n filename,\n only,\n code\n );\n\n if (newEntrypoint.evaluated) {\n log('✅ file has been already evaluated');\n return newEntrypoint;\n }\n\n if (newEntrypoint.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return newEntrypoint;\n }\n\n return newEntrypoint;\n }\n\n resolveDependency = (id: string): IEntrypointDependency => {\n const cached = this.entrypoint.getDependency(id);\n invariant(!(cached instanceof Promise), 'Dependency is not resolved yet');\n\n if (cached) {\n return cached;\n }\n\n if (!this.ignored) {\n this.debug(\n '❌ import has not been resolved during prepare stage. Fallback to Node.js resolver'\n );\n }\n\n const extensions = this.moduleImpl._extensions;\n const added: string[] = [];\n\n try {\n // Check for supported extensions\n this.extensions.forEach((ext) => {\n if (ext in extensions) {\n return;\n }\n\n // When an extension is not supported, add it\n // And keep track of it to clean it up after resolving\n // Use noop for the transform function since we handle it\n extensions[ext] = NOOP;\n added.push(ext);\n });\n\n const { filename } = this;\n\n const resolved = this.moduleImpl._resolveFilename(id, {\n id: filename,\n filename,\n paths: this.moduleImpl._nodeModulePaths(path.dirname(filename)),\n });\n\n return {\n source: id,\n only: ['*'],\n resolved,\n };\n } finally {\n // Cleanup the extensions we added to restore previous behaviour\n added.forEach((ext) => delete extensions[ext]);\n }\n };\n\n protected createChild(entrypoint: Entrypoint): Module {\n return new Module(this.services, entrypoint, this, this.moduleImpl);\n }\n}\n"],"mappings":";;;;;;AAaA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,GAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAEA,IAAAI,YAAA,GAAAJ,OAAA;AAIAA,OAAA;AAEA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAGA,IAAAO,2BAAA,GAAAP,OAAA;AAEA,IAAAQ,gBAAA,GAAAR,OAAA;AAAuD,SAAAD,uBAAAU,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AA9BvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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GAAGvG,IAAI;QACtBqG,KAAK,CAAC3E,IAAI,CAAC6E,GAAG,CAAC;MACjB,CAAC,CAAC;MAEF,MAAM;QAAEtD;MAAS,CAAC,GAAG,IAAI;MAEzB,MAAMrC,QAAQ,GAAG,IAAI,CAAC8B,UAAU,CAAC8D,gBAAgB,CAAC7F,EAAE,EAAE;QACpDA,EAAE,EAAEsC,QAAQ;QACZA,QAAQ;QACRwD,KAAK,EAAE,IAAI,CAAC/D,UAAU,CAACgE,gBAAgB,CAAC1H,aAAI,CAAC0F,OAAO,CAACzB,QAAQ,CAAC;MAChE,CAAC,CAAC;MAEF,OAAO;QACLzB,MAAM,EAAEb,EAAE;QACVkB,IAAI,EAAE,CAAC,GAAG,CAAC;QACXjB;MACF,CAAC;IACH,CAAC,SAAS;MACR;MACAyF,KAAK,CAACC,OAAO,CAAEC,GAAG,IAAK,OAAOjD,UAAU,CAACiD,GAAG,CAAC,CAAC;IAChD;EACF,CAAC;EAESrE,WAAWA,CAACP,UAAsB,EAAU;IACpD,OAAO,IAAIZ,MAAM,CAAC,IAAI,CAACyB,QAAQ,EAAEb,UAAU,EAAE,IAAI,EAAE,IAAI,CAACe,UAAU,CAAC;EACrE;AACF;AAAC9E,OAAA,CAAAmD,MAAA,GAAAA,MAAA"}
1
+ {"version":3,"file":"module.js","names":["_fs","_interopRequireDefault","require","_module","_path","_vm","_tsInvariant","_shared","_Entrypoint","_Entrypoint2","_UnprocessedEntrypointError","_createVmContext","obj","__esModule","default","DefaultModuleImplementation","exports","NativeModule","builtins","assert","buffer","child_process","cluster","console","constants","crypto","dgram","dns","domain","events","fs","http","https","module","net","os","path","punycode","process","querystring","readline","repl","stream","string_decoder","sys","timers","tls","tty","url","util","vm","zlib","NOOP","getUncached","cached","test","cachedSet","Set","split","has","filter","t","resolve","id","resolved","resolveDependency","invariant","Module","callstack","isEvaluated","Object","assign","debug","dependency","isAbsolute","Error","source","dependencies","push","entrypoint","getEntrypoint","only","evaluated","isSuperSet","evaluatedOnly","m","createChild","evaluate","ensure","bind","entrypointRef","constructor","services","parentModule","moduleImpl","_parentModule$ignored","_entrypoint$ignored","cache","isFeatureEnabled","options","pluginOptions","features","name","WeakRef","idx","filename","log","extend","parentIsIgnored","ignored","extensions","value","deref","assertTransformed","get","evaluatedCreated","supersededWith","add","createEvaluated","transformedCode","JSON","parse","context","teardown","createVmContext","__wyw_dynamic_import","__dirname","dirname","overrideContext","script","Script","runInContext","e","isUnprocessedEntrypointError","EvalError","message","join","_entrypoint$evaluated","extension","extname","includes","newEntrypoint","readFileSync","stack","getStack","_entrypoint$only","uncachedExports","length","code","Entrypoint","createRoot","getDependency","Promise","_extensions","added","forEach","ext","_resolveFilename","paths","_nodeModulePaths"],"sources":["../src/module.ts"],"sourcesContent":["/**\n * This is a custom implementation for the module system for evaluating code,\n * used for resolving values for dependencies interpolated in `css` or `styled`.\n *\n * This serves 2 purposes:\n * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`\n * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds\n *\n * We also use it to transpile the code with Babel by default.\n * We also store source maps for it to provide correct error stacktraces.\n *\n */\n\nimport fs from 'fs';\nimport NativeModule from 'module';\nimport path from 'path';\nimport vm from 'vm';\n\nimport { invariant } from 'ts-invariant';\n\nimport { isFeatureEnabled, type Debugger } from '@wyw-in-js/shared';\n\nimport './utils/dispose-polyfill';\nimport type { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport { getStack, isSuperSet } from './transform/Entrypoint.helpers';\nimport type { IEntrypointDependency } from './transform/Entrypoint.types';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';\nimport type { Services } from './transform/types';\nimport { createVmContext } from './vm/createVmContext';\n\ntype HiddenModuleMembers = {\n _extensions: Record<string, () => void>;\n _resolveFilename: (\n id: string,\n options: { filename: string; id: string; paths: string[] }\n ) => string;\n _nodeModulePaths(filename: string): string[];\n};\n\nexport const DefaultModuleImplementation = NativeModule as typeof NativeModule &\n HiddenModuleMembers;\n\n// Supported node builtins based on the modules polyfilled by webpack\n// `true` means module is polyfilled, `false` means module is empty\nconst builtins = {\n assert: true,\n buffer: true,\n child_process: false,\n cluster: false,\n console: true,\n constants: true,\n crypto: true,\n dgram: false,\n dns: false,\n domain: true,\n events: true,\n fs: false,\n http: true,\n https: true,\n module: false,\n net: false,\n os: true,\n path: true,\n punycode: true,\n process: true,\n querystring: true,\n readline: false,\n repl: false,\n stream: true,\n string_decoder: true,\n sys: true,\n timers: true,\n tls: false,\n tty: true,\n url: true,\n util: true,\n vm: true,\n zlib: true,\n};\n\nconst NOOP = () => {};\n\nfunction getUncached(cached: string | string[], test: string[]): string[] {\n const cachedSet = new Set(\n typeof cached === 'string' ? cached.split(',') : cached\n );\n\n if (cachedSet.has('*')) {\n return [];\n }\n\n return test.filter((t) => !cachedSet.has(t));\n}\n\nfunction resolve(\n this: { resolveDependency: (id: string) => IEntrypointDependency },\n id: string\n): string {\n const { resolved } = this.resolveDependency(id);\n invariant(resolved, `Unable to resolve \"${id}\"`);\n return resolved;\n}\n\nexport class Module {\n public readonly callstack: string[] = [];\n\n public readonly debug: Debugger;\n\n public readonly dependencies: string[];\n\n public readonly extensions: string[];\n\n public readonly filename: string;\n\n public id: string;\n\n public readonly idx: string;\n\n public readonly ignored: boolean;\n\n public isEvaluated: boolean = false;\n\n public readonly parentIsIgnored: boolean;\n\n public require: {\n (id: string): unknown;\n ensure: () => void;\n resolve: (id: string) => string;\n } = Object.assign(\n (id: string) => {\n if (id in builtins) {\n // The module is in the allowed list of builtin node modules\n // Ideally we should prevent importing them, but webpack polyfills some\n // So we check for the list of polyfills to determine which ones to support\n if (builtins[id as keyof typeof builtins]) {\n this.debug('require', `builtin '${id}'`);\n return require(id);\n }\n\n return null;\n }\n\n // Resolve module id (and filename) relatively to parent module\n const dependency = this.resolveDependency(id);\n if (dependency.resolved === id && !path.isAbsolute(id)) {\n // The module is a builtin node modules, but not in the allowed list\n throw new Error(\n `Unable to import \"${id}\". Importing Node builtins is not supported in the sandbox.`\n );\n }\n\n invariant(\n dependency.resolved,\n `Dependency ${dependency.source} cannot be resolved`\n );\n\n this.dependencies.push(id);\n\n this.debug('require', `${id} -> ${dependency.resolved}`);\n\n const entrypoint = this.getEntrypoint(\n dependency.resolved,\n dependency.only,\n this.debug\n );\n\n if (entrypoint === null) {\n return dependency.resolved;\n }\n\n if (\n entrypoint.evaluated ||\n isSuperSet(entrypoint.evaluatedOnly, dependency.only)\n ) {\n return entrypoint.exports;\n }\n\n const m = this.createChild(entrypoint);\n m.evaluate();\n\n return entrypoint.exports;\n },\n {\n ensure: NOOP,\n resolve: resolve.bind(this),\n }\n );\n\n public resolve = resolve.bind(this);\n\n private cache: TransformCacheCollection;\n\n #entrypointRef: WeakRef<Entrypoint> | Entrypoint;\n\n constructor(\n private services: Services,\n entrypoint: Entrypoint,\n parentModule?: Module,\n private moduleImpl: HiddenModuleMembers = DefaultModuleImplementation\n ) {\n this.cache = services.cache;\n this.#entrypointRef = isFeatureEnabled(\n services.options.pluginOptions.features,\n 'useWeakRefInEval',\n entrypoint.name\n )\n ? new WeakRef(entrypoint)\n : entrypoint;\n this.idx = entrypoint.idx;\n this.id = entrypoint.name;\n this.filename = entrypoint.name;\n this.dependencies = [];\n this.debug = entrypoint.log.extend('module');\n this.parentIsIgnored = parentModule?.ignored ?? false;\n this.ignored = entrypoint.ignored ?? this.parentIsIgnored;\n\n if (parentModule) {\n this.callstack = [entrypoint.name, ...parentModule.callstack];\n } else {\n this.callstack = [entrypoint.name];\n }\n\n this.extensions = services.options.pluginOptions.extensions;\n\n this.debug('init', entrypoint.name);\n }\n\n public get exports() {\n return this.entrypoint.exports;\n }\n\n public set exports(value) {\n this.entrypoint.exports = value;\n\n this.debug('the whole exports was overridden with %O', value);\n }\n\n protected get entrypoint(): Entrypoint {\n const entrypoint =\n this.#entrypointRef instanceof WeakRef\n ? this.#entrypointRef.deref()\n : this.#entrypointRef;\n invariant(entrypoint, `Module ${this.idx} is disposed`);\n return entrypoint;\n }\n\n evaluate(): void {\n const { entrypoint } = this;\n entrypoint.assertTransformed();\n\n const cached = this.cache.get('entrypoints', entrypoint.name)!;\n let evaluatedCreated = false;\n if (!entrypoint.supersededWith) {\n this.cache.add(\n 'entrypoints',\n entrypoint.name,\n entrypoint.createEvaluated()\n );\n evaluatedCreated = true;\n }\n\n const { transformedCode: source } = entrypoint;\n const { pluginOptions } = this.services.options;\n\n if (!source) {\n this.debug(`evaluate`, 'there is nothing to evaluate');\n return;\n }\n\n if (this.isEvaluated) {\n this.debug('evaluate', `is already evaluated`);\n return;\n }\n\n this.debug('evaluate');\n this.debug.extend('source')('%s', source);\n\n this.isEvaluated = true;\n\n const { filename } = this;\n\n if (/\\.json$/.test(filename)) {\n // For JSON files, parse it to a JS object similar to Node\n this.exports = JSON.parse(source);\n return;\n }\n\n const { context, teardown } = createVmContext(\n filename,\n pluginOptions.features,\n {\n module: this,\n exports: entrypoint.exports,\n require: this.require,\n __wyw_dynamic_import: async (id: string) => this.require(id),\n __dirname: path.dirname(filename),\n },\n pluginOptions.overrideContext\n );\n\n try {\n const script = new vm.Script(\n `(function (exports) { ${source}\\n})(exports);`,\n {\n filename,\n }\n );\n\n script.runInContext(context);\n } catch (e) {\n this.isEvaluated = false;\n if (evaluatedCreated) {\n this.cache.add('entrypoints', entrypoint.name, cached);\n }\n\n if (isUnprocessedEntrypointError(e)) {\n // It will be handled by evalFile scenario\n throw e;\n }\n\n if (e instanceof EvalError) {\n this.debug('%O', e);\n\n throw e;\n }\n\n this.debug('%O\\n%O', e, this.callstack);\n throw new EvalError(\n `${(e as Error).message} in${this.callstack.join('\\n| ')}\\n`\n );\n } finally {\n teardown();\n }\n }\n\n getEntrypoint(\n filename: string,\n only: string[],\n log: Debugger\n ): Entrypoint | IEvaluatedEntrypoint | null {\n const extension = path.extname(filename);\n if (extension !== '.json' && !this.extensions.includes(extension)) {\n return null;\n }\n\n const entrypoint = this.cache.get('entrypoints', filename);\n if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {\n log('✅ file has been already evaluated');\n return entrypoint;\n }\n\n if (entrypoint?.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return entrypoint;\n }\n\n if (this.ignored) {\n log(\n '✅ one of the parent files has been ignored during prepare stage. Original code will be used'\n );\n\n const newEntrypoint = this.entrypoint.createChild(\n filename,\n ['*'],\n fs.readFileSync(filename, 'utf-8')\n );\n\n if (newEntrypoint === 'loop') {\n const stack = getStack(this.entrypoint);\n throw new Error(\n `Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`\n );\n }\n\n return newEntrypoint;\n }\n\n // Requested file can be already prepared for evaluation on the stage 1\n if (only && entrypoint) {\n const uncachedExports = getUncached(entrypoint.only ?? [], only);\n if (uncachedExports.length === 0) {\n log('✅ ready for evaluation');\n return entrypoint;\n }\n\n log(\n '❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)',\n uncachedExports,\n entrypoint.only\n );\n } else {\n log('❌ file has not been processed during prepare stage');\n }\n\n // If code wasn't extracted from cache, it indicates that we were unable\n // to process some of the imports on stage1. Let's try to reprocess.\n const code = fs.readFileSync(filename, 'utf-8');\n const newEntrypoint = Entrypoint.createRoot(\n this.services,\n filename,\n only,\n code\n );\n\n if (newEntrypoint.evaluated) {\n log('✅ file has been already evaluated');\n return newEntrypoint;\n }\n\n if (newEntrypoint.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return newEntrypoint;\n }\n\n return newEntrypoint;\n }\n\n resolveDependency = (id: string): IEntrypointDependency => {\n const cached = this.entrypoint.getDependency(id);\n invariant(!(cached instanceof Promise), 'Dependency is not resolved yet');\n\n if (cached) {\n return cached;\n }\n\n if (!this.ignored) {\n this.debug(\n '❌ import has not been resolved during prepare stage. Fallback to Node.js resolver'\n );\n }\n\n const extensions = this.moduleImpl._extensions;\n const added: string[] = [];\n\n try {\n // Check for supported extensions\n this.extensions.forEach((ext) => {\n if (ext in extensions) {\n return;\n }\n\n // When an extension is not supported, add it\n // And keep track of it to clean it up after resolving\n // Use noop for the transform function since we handle it\n extensions[ext] = NOOP;\n added.push(ext);\n });\n\n const { filename } = this;\n\n const resolved = this.moduleImpl._resolveFilename(id, {\n id: filename,\n filename,\n paths: this.moduleImpl._nodeModulePaths(path.dirname(filename)),\n });\n\n return {\n source: id,\n only: ['*'],\n resolved,\n };\n } finally {\n // Cleanup the extensions we added to restore previous behaviour\n added.forEach((ext) => delete extensions[ext]);\n }\n };\n\n protected createChild(entrypoint: Entrypoint): Module {\n return new Module(this.services, entrypoint, this, this.moduleImpl);\n }\n}\n"],"mappings":";;;;;;AAaA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,GAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAEA,IAAAI,YAAA,GAAAJ,OAAA;AAEA,IAAAK,OAAA,GAAAL,OAAA;AAEAA,OAAA;AAEA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,YAAA,GAAAP,OAAA;AAGA,IAAAQ,2BAAA,GAAAR,OAAA;AAEA,IAAAS,gBAAA,GAAAT,OAAA;AAAuD,SAAAD,uBAAAW,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AA9BvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA8BO,MAAMG,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAGE,eACtB;;AAErB;AACA;AACA,MAAMC,QAAQ,GAAG;EACfC,MAAM,EAAE,IAAI;EACZC,MAAM,EAAE,IAAI;EACZC,aAAa,EAAE,KAAK;EACpBC,OAAO,EAAE,KAAK;EAC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G,IAAI;QACtBsG,KAAK,CAAC5E,IAAI,CAAC8E,GAAG,CAAC;MACjB,CAAC,CAAC;MAEF,MAAM;QAAEnD;MAAS,CAAC,GAAG,IAAI;MAEzB,MAAMzC,QAAQ,GAAG,IAAI,CAAC8B,UAAU,CAAC+D,gBAAgB,CAAC9F,EAAE,EAAE;QACpDA,EAAE,EAAE0C,QAAQ;QACZA,QAAQ;QACRqD,KAAK,EAAE,IAAI,CAAChE,UAAU,CAACiE,gBAAgB,CAAC3H,aAAI,CAAC2F,OAAO,CAACtB,QAAQ,CAAC;MAChE,CAAC,CAAC;MAEF,OAAO;QACL7B,MAAM,EAAEb,EAAE;QACVkB,IAAI,EAAE,CAAC,GAAG,CAAC;QACXjB;MACF,CAAC;IACH,CAAC,SAAS;MACR;MACA0F,KAAK,CAACC,OAAO,CAAEC,GAAG,IAAK,OAAO9C,UAAU,CAAC8C,GAAG,CAAC,CAAC;IAChD;EACF,CAAC;EAEStE,WAAWA,CAACP,UAAsB,EAAU;IACpD,OAAO,IAAIZ,MAAM,CAAC,IAAI,CAACyB,QAAQ,EAAEb,UAAU,EAAE,IAAI,EAAE,IAAI,CAACe,UAAU,CAAC;EACrE;AACF;AAAC9E,OAAA,CAAAmD,MAAA,GAAAA,MAAA"}
@@ -32,7 +32,8 @@ function loadWywOptions(overrides = defaultOverrides) {
32
32
  globalCache: true,
33
33
  happyDOM: true,
34
34
  softErrors: false,
35
- useBabelConfigs: true
35
+ useBabelConfigs: true,
36
+ useWeakRefInEval: true
36
37
  };
37
38
  const options = {
38
39
  displayName: false,
@@ -1 +1 @@
1
- {"version":3,"file":"loadWywOptions.js","names":["_cosmiconfig","require","_shaker","searchPlaces","explorerSync","cosmiconfigSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","options","displayName","evaluate","extensions","action","shaker","test","filename","code","highPriorityPlugins","config","features","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\n\nimport { shaker } from '../../shaker';\nimport type { PluginOptions } from '../../types';\n\nconst searchPlaces = [\n `.wyw-in-jsrc`,\n `.wyw-in-jsrc.json`,\n `.wyw-in-jsrc.yaml`,\n `.wyw-in-jsrc.yml`,\n `.wyw-in-jsrc.js`,\n `.wyw-in-jsrc.cjs`,\n `.config/wyw-in-jsrc`,\n `.config/wyw-in-jsrc.json`,\n `.config/wyw-in-jsrc.yaml`,\n `.config/wyw-in-jsrc.yml`,\n `.config/wyw-in-jsrc.js`,\n `.config/wyw-in-jsrc.cjs`,\n `wyw-in-js.config.js`,\n `wyw-in-js.config.cjs`,\n];\n\nconst explorerSync = cosmiconfigSync('wyw-in-js', { searchPlaces });\n\nexport type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {\n features?: Partial<FeatureFlags>;\n};\n\nconst cache = new WeakMap<Partial<PartialOptions>, StrictOptions>();\nconst defaultOverrides = {};\nconst nodeModulesRegExp = /[\\\\/]node_modules[\\\\/]/;\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const { configFile, ignore, rules, babelOptions = {}, ...rest } = overrides;\n\n const result =\n // eslint-disable-next-line no-nested-ternary\n configFile === false\n ? undefined\n : configFile !== undefined\n ? explorerSync.load(configFile)\n : explorerSync.search();\n\n const defaultFeatures: FeatureFlags = {\n dangerousCodeRemover: true,\n globalCache: true,\n happyDOM: true,\n softErrors: false,\n useBabelConfigs: true,\n };\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n rules: rules ?? [\n {\n action: shaker,\n },\n {\n // The old `ignore` option is used as a default value for `ignore` rule.\n test: ignore ?? nodeModulesRegExp,\n action: 'ignore',\n },\n {\n // Do not ignore ES-modules\n test: (filename, code) => {\n if (!nodeModulesRegExp.test(filename)) {\n return false;\n }\n\n // If a file contains `export` or `import` keywords, we assume it's an ES-module\n return /(?:^|\\*\\/|;|})\\s*(?:export|import)[\\s{]/m.test(code);\n },\n action: shaker,\n },\n ],\n babelOptions,\n highPriorityPlugins: ['module-resolver'],\n ...(result ? result.config : {}),\n ...rest,\n features: {\n ...defaultFeatures,\n ...(result ? result.config.features : {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,OAAA,GAAAD,OAAA;AAGA,MAAME,YAAY,GAAG,CAClB,cAAa,EACb,mBAAkB,EAClB,mBAAkB,EAClB,kBAAiB,EACjB,iBAAgB,EAChB,kBAAiB,EACjB,qBAAoB,EACpB,0BAAyB,EACzB,0BAAyB,EACzB,yBAAwB,EACxB,wBAAuB,EACvB,yBAAwB,EACxB,qBAAoB,EACpB,sBAAqB,CACvB;AAED,MAAMC,YAAY,GAAG,IAAAC,4BAAe,EAAC,WAAW,EAAE;EAAEF;AAAa,CAAC,CAAC;AAMnE,MAAMG,KAAK,GAAG,IAAIC,OAAO,CAAyC,CAAC;AACnE,MAAMC,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAMC,iBAAiB,GAAG,wBAAwB;AAE3C,SAASC,cAAcA,CAC5BC,SAAyB,GAAGH,gBAAgB,EAC7B;EACf,IAAIF,KAAK,CAACM,GAAG,CAACD,SAAS,CAAC,EAAE;IACxB,OAAOL,KAAK,CAACO,GAAG,CAACF,SAAS,CAAC;EAC7B;EAEA,MAAM;IAAEG,UAAU;IAAEC,MAAM;IAAEC,KAAK;IAAEC,YAAY,GAAG,CAAC,CAAC;IAAE,GAAGC;EAAK,CAAC,GAAGP,SAAS;EAE3E,MAAMQ,MAAM;EACV;E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,CAAC;MACzC,GAAGtB,IAAI,CAACsB;IACV;EACF,CAAC;EAEDlC,KAAK,CAACmC,GAAG,CAAC9B,SAAS,EAAEkB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB"}
1
+ {"version":3,"file":"loadWywOptions.js","names":["_cosmiconfig","require","_shaker","searchPlaces","explorerSync","cosmiconfigSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","useWeakRefInEval","options","displayName","evaluate","extensions","action","shaker","test","filename","code","highPriorityPlugins","config","features","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\n\nimport { shaker } from '../../shaker';\nimport type { PluginOptions } from '../../types';\n\nconst searchPlaces = [\n `.wyw-in-jsrc`,\n `.wyw-in-jsrc.json`,\n `.wyw-in-jsrc.yaml`,\n `.wyw-in-jsrc.yml`,\n `.wyw-in-jsrc.js`,\n `.wyw-in-jsrc.cjs`,\n `.config/wyw-in-jsrc`,\n `.config/wyw-in-jsrc.json`,\n `.config/wyw-in-jsrc.yaml`,\n `.config/wyw-in-jsrc.yml`,\n `.config/wyw-in-jsrc.js`,\n `.config/wyw-in-jsrc.cjs`,\n `wyw-in-js.config.js`,\n `wyw-in-js.config.cjs`,\n];\n\nconst explorerSync = cosmiconfigSync('wyw-in-js', { searchPlaces });\n\nexport type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {\n features?: Partial<FeatureFlags>;\n};\n\nconst cache = new WeakMap<Partial<PartialOptions>, StrictOptions>();\nconst defaultOverrides = {};\nconst nodeModulesRegExp = /[\\\\/]node_modules[\\\\/]/;\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const { configFile, ignore, rules, babelOptions = {}, ...rest } = overrides;\n\n const result =\n // eslint-disable-next-line no-nested-ternary\n configFile === false\n ? undefined\n : configFile !== undefined\n ? explorerSync.load(configFile)\n : explorerSync.search();\n\n const defaultFeatures: FeatureFlags = {\n dangerousCodeRemover: true,\n globalCache: true,\n happyDOM: true,\n softErrors: false,\n useBabelConfigs: true,\n useWeakRefInEval: true,\n };\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n rules: rules ?? [\n {\n action: shaker,\n },\n {\n // The old `ignore` option is used as a default value for `ignore` rule.\n test: ignore ?? nodeModulesRegExp,\n action: 'ignore',\n },\n {\n // Do not ignore ES-modules\n test: (filename, code) => {\n if (!nodeModulesRegExp.test(filename)) {\n return false;\n }\n\n // If a file contains `export` or `import` keywords, we assume it's an ES-module\n return /(?:^|\\*\\/|;|})\\s*(?:export|import)[\\s{]/m.test(code);\n },\n action: shaker,\n },\n ],\n babelOptions,\n highPriorityPlugins: ['module-resolver'],\n ...(result ? result.config : {}),\n ...rest,\n features: {\n ...defaultFeatures,\n ...(result ? result.config.features : {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,OAAA,GAAAD,OAAA;AAGA,MAAME,YAAY,GAAG,CAClB,cAAa,EACb,mBAAkB,EAClB,mBAAkB,EAClB,kBAAiB,EACjB,iBAAgB,EAChB,kBAAiB,EACjB,qBAAoB,EACpB,0BAAyB,EACzB,0BAAyB,EACzB,yBAAwB,EACxB,wBAAuB,EACvB,yBAAwB,EACxB,qBAAoB,EACpB,sBAAqB,CACvB;AAED,MAAMC,YAAY,GAAG,IAAAC,4BAAe,EAAC,WAAW,EAAE;EAAEF;AAAa,CAAC,CAAC;AAMnE,MAAMG,KAAK,GAAG,IAA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AC7B,iBAAiB,CAAC2B,IAAI,CAACC,QAAQ,CAAC,EAAE;UACrC,OAAO,KAAK;QACd;;QAEA;QACA,OAAO,0CAA0C,CAACD,IAAI,CAACE,IAAI,CAAC;MAC9D,CAAC;MACDJ,MAAM,EAAEC;IACV,CAAC,CACF;IACDlB,YAAY;IACZsB,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;IACxC,IAAIpB,MAAM,GAAGA,MAAM,CAACqB,MAAM,GAAG,CAAC,CAAC,CAAC;IAChC,GAAGtB,IAAI;IACPuB,QAAQ,EAAE;MACR,GAAGlB,eAAe;MAClB,IAAIJ,MAAM,GAAGA,MAAM,CAACqB,MAAM,CAACC,QAAQ,GAAG,CAAC,CAAC,CAAC;MACzC,GAAGvB,IAAI,CAACuB;IACV;EACF,CAAC;EAEDnC,KAAK,CAACoC,GAAG,CAAC/B,SAAS,EAAEmB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB"}
@@ -167,7 +167,7 @@ function getBuilderForIdentifier(definedProcessor, path, imports, options) {
167
167
  }
168
168
  const replacer = (replacement, isPure) => {
169
169
  (0, _scopeHelpers.mutate)(prev, p => {
170
- p.replaceWith(replacement);
170
+ p.replaceWith(typeof replacement === 'function' ? replacement(p) : replacement);
171
171
  if (isPure) {
172
172
  p.addComment('leading', '#__PURE__');
173
173
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getTagProcessor.js","names":["_fs","require","_path","_core","_helperModuleImports","_processorUtils","_shared","_collectExportsAndImports","_collectTemplateDependencies","_getSource","_isNotNull","_scopeHelpers","_traversalCache","last","arr","length","zip","arr1","arr2","result","i","push","buildCodeFrameError","path","message","Error","definedTagsCache","Map","getDefinedTagsFromPackage","pkgName","filename","_packageJSON$wywInJ","has","get","packageJSONPath","findPackageJSON","undefined","packageDir","dirname","packageJSON","JSON","parse","readFileSync","definedTags","tags","normalizedTags","Object","entries","reduce","acc","key","value","startsWith","join","resolve","paths","set","isValidProcessorClass","module","BaseProcessor","constructor","getProcessorFromPackage","packageName","tagName","processorPath","Processor","default","getProcessorFromFile","getProcessorForImport","imported","source","options","_options$tagResolver","tagResolver","customFile","processor","getBuilderForIdentifier","definedProcessor","imports","_tagPath$parentPath","tagSource","tagPath","parentPath","isMemberExpression","property","node","params","prev","current","_current","_current2","_current3","_current4","isSequenceExpression","expressions","isCallExpression","callee","args","cookedArgs","map","arg","buildError","bind","isExpression","type","getSource","extracted","extractExpression","evaluate","filter","isNotNull","object","isIdentifier","computed","name","isStringLiteral","isTaggedTemplateExpression","tag","quasis","expressionValues","collectTemplateDependencies","replacer","replacement","isPure","mutate","p","replaceWith","addComment","importHelpers","addDefaultImport","importedSource","nameHint","addDefault","addNamedImport","addNamed","astService","Proxy","t","target","prop","receiver","Reflect","_tagPath$node$loc","loc","getDisplayName","idx","displayName","parent","findParent","isObjectProperty","isJSXOpeningElement","isVariableDeclarator","toString","keyPath","isJSXIdentifier","id","basename","test","replace","isTagReferenced","isReferenced","referencePaths","scope","getBinding","counters","WeakMap","getNextIndex","state","_counters$get","counter","getDefinedProcessors","cache","getTraversalCache","defined","forEach","local","createProcessorInstance","fileContext","_cache$get","builder","e","SKIP","applyProcessors","callback","collectExportsAndImports","explicitImport","definedProcessors","usages","idName","_path$scope$getBindin","includes","split","objBinding","identifier","sort","a","b","_a$identifier$node$st","_b$identifier$node$st","start","usage","instance"],"sources":["../../src/utils/getTagProcessor.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { basename, dirname, join } from 'path';\n\nimport { types as t } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport type { NodePath } from '@babel/traverse';\nimport type {\n Expression,\n Identifier,\n MemberExpression,\n Program,\n SourceLocation,\n} from '@babel/types';\n\nimport { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Param,\n Params,\n IFileContext,\n TagSource,\n} from '@wyw-in-js/processor-utils';\nimport { findPackageJSON } from '@wyw-in-js/shared';\nimport type { ExpressionValue, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { IImport } from './collectExportsAndImports';\nimport {\n collectExportsAndImports,\n explicitImport,\n} from './collectExportsAndImports';\nimport {\n collectTemplateDependencies,\n extractExpression,\n} from './collectTemplateDependencies';\nimport { getSource } from './getSource';\nimport { isNotNull } from './isNotNull';\nimport { mutate } from './scopeHelpers';\nimport { getTraversalCache } from './traversalCache';\n\ntype BuilderArgs = ConstructorParameters<typeof BaseProcessor> extends [\n Params,\n TagSource,\n typeof t,\n SourceLocation | null,\n (replacement: Expression, isPure: boolean) => void,\n ...infer T,\n]\n ? T\n : never;\n\ntype Builder = (...args: BuilderArgs) => BaseProcessor;\n\ntype DefinedProcessor = [ProcessorClass, TagSource];\ntype DefinedProcessors = Map<string, DefinedProcessor>;\n\nexport type ProcessorClass = new (\n ...args: ConstructorParameters<typeof BaseProcessor>\n) => BaseProcessor;\n\nconst last = <T>(arr: T[]): T | undefined => arr[arr.length - 1];\n\nfunction zip<T1, T2>(arr1: T1[], arr2: T2[]) {\n const result: (T1 | T2)[] = [];\n for (let i = 0; i < arr1.length; i++) {\n result.push(arr1[i]);\n if (arr2[i]) result.push(arr2[i]);\n }\n\n return result;\n}\n\nfunction buildCodeFrameError(path: NodePath, message: string): Error {\n try {\n return path.buildCodeFrameError(message);\n } catch {\n return new Error(message);\n }\n}\n\nconst definedTagsCache = new Map<string, Record<string, string> | undefined>();\nconst getDefinedTagsFromPackage = (\n pkgName: string,\n filename: string | null | undefined\n): Record<string, string> | undefined => {\n if (definedTagsCache.has(pkgName)) {\n return definedTagsCache.get(pkgName);\n }\n\n const packageJSONPath = findPackageJSON(pkgName, filename);\n if (!packageJSONPath) {\n return undefined;\n }\n\n const packageDir = dirname(packageJSONPath);\n const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'));\n const definedTags: Record<string, string> | undefined =\n packageJSON['wyw-in-js']?.tags;\n\n const normalizedTags = definedTags\n ? Object.entries(definedTags).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: value.startsWith('.')\n ? join(packageDir, value)\n : require.resolve(value, { paths: [packageDir] }),\n }),\n {} as Record<string, string>\n )\n : undefined;\n\n definedTagsCache.set(pkgName, normalizedTags);\n\n return normalizedTags;\n};\n\nfunction isValidProcessorClass(module: unknown): module is ProcessorClass {\n return module instanceof BaseProcessor.constructor;\n}\n\nfunction getProcessorFromPackage(\n packageName: string,\n tagName: string,\n filename: string | null | undefined\n): ProcessorClass | null {\n const definedTags = getDefinedTagsFromPackage(packageName, filename);\n const processorPath = definedTags?.[tagName];\n if (!processorPath) {\n return null;\n }\n\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nfunction getProcessorFromFile(processorPath: string): ProcessorClass | null {\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nexport function getProcessorForImport(\n { imported, source }: IImport,\n filename: string | null | undefined,\n options: Pick<StrictOptions, 'tagResolver'>\n): [ProcessorClass | null, TagSource] {\n const tagResolver = options.tagResolver ?? (() => null);\n\n const customFile = tagResolver(source, imported);\n const processor = customFile\n ? getProcessorFromFile(customFile)\n : getProcessorFromPackage(source, imported, filename);\n return [processor, { imported, source }];\n}\n\nfunction getBuilderForIdentifier(\n definedProcessor: DefinedProcessor,\n path: NodePath<Identifier>,\n imports: IImport[],\n options: Pick<StrictOptions, 'evaluate'>\n): Builder | null {\n const [Processor, tagSource] = definedProcessor;\n let tagPath: NodePath<Identifier | MemberExpression> = path;\n if (tagPath.parentPath?.isMemberExpression({ property: tagPath.node })) {\n tagPath = tagPath.parentPath;\n }\n\n if (!Processor || !tagSource || !tagPath) {\n return null;\n }\n\n const params: Param[] = [['callee', tagPath.node]];\n let prev: NodePath = tagPath;\n let current: NodePath | null = tagPath.parentPath;\n while (current && current !== path) {\n if (\n current?.isSequenceExpression() &&\n last(current.node.expressions) === prev.node\n ) {\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isCallExpression({ callee: prev.node })) {\n const args = current.get('arguments');\n const cookedArgs = args\n .map((arg) => {\n const buildError = arg.buildCodeFrameError.bind(arg);\n if (!arg.isExpression()) {\n throw buildError(`Unexpected type of an argument ${arg.type}`);\n }\n const source = getSource(arg);\n const extracted = extractExpression(arg, options.evaluate, imports);\n return {\n ...extracted,\n source,\n buildCodeFrameError: buildError,\n } as ExpressionValue;\n })\n .filter(isNotNull);\n\n params.push(['call', ...cookedArgs]);\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isMemberExpression({ object: prev.node })) {\n const property = current.get('property');\n if (property.isIdentifier() && !current.node.computed) {\n params.push(['member', property.node.name]);\n } else if (property.isStringLiteral()) {\n params.push(['member', property.node.value]);\n } else {\n throw property.buildCodeFrameError(`Unexpected type of a property`);\n }\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isTaggedTemplateExpression({ tag: prev.node })) {\n const [quasis, expressionValues] = collectTemplateDependencies(\n current,\n options.evaluate\n );\n params.push(['template', zip(quasis, expressionValues)]);\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n break;\n }\n\n const replacer = (replacement: Expression, isPure: boolean) => {\n mutate(prev, (p) => {\n p.replaceWith(replacement);\n if (isPure) {\n p.addComment('leading', '#__PURE__');\n }\n });\n };\n\n const importHelpers = {\n addDefaultImport: (importedSource: string, nameHint?: string) =>\n addDefault(path, importedSource, { nameHint }),\n addNamedImport: (\n name: string,\n importedSource: string,\n nameHint: string = name\n ) => addNamed(path, name, importedSource, { nameHint }),\n };\n\n type AstService = typeof t & typeof importHelpers;\n\n const astService = new Proxy<AstService>(t as AstService, {\n get(target, prop, receiver) {\n if (prop in importHelpers) {\n return importHelpers[prop as keyof typeof importHelpers];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n });\n\n return (...args: BuilderArgs) =>\n new Processor(\n params,\n tagSource,\n astService,\n tagPath.node.loc ?? null,\n replacer,\n ...args\n );\n}\n\nfunction getDisplayName(\n path: NodePath<Identifier>,\n idx: number,\n filename?: string | null\n): string {\n let displayName: string | undefined;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isObjectProperty()) {\n if ('name' in parent.node.key) {\n displayName = parent.node.key.name;\n } else if ('value' in parent.node.key) {\n displayName = parent.node.key.value.toString();\n } else {\n const keyPath = parent.get('key');\n displayName = getSource(keyPath);\n }\n } else if (parent.isJSXOpeningElement()) {\n const name = parent.get('name');\n if (name.isJSXIdentifier()) {\n displayName = name.node.name;\n }\n } else if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n if (id.isIdentifier()) {\n displayName = id.node.name;\n }\n }\n }\n\n if (!displayName) {\n // Try to derive the path from the filename\n displayName = basename(filename ?? 'unknown');\n\n if (filename && /^index\\.[a-z\\d]+$/.test(displayName)) {\n // If the file name is 'index', better to get name from parent folder\n displayName = basename(dirname(filename));\n }\n\n // Remove the file extension\n displayName = displayName.replace(/\\.[a-z\\d]+$/, '');\n\n if (displayName) {\n displayName += idx;\n } else {\n throw new Error(\n \"Couldn't determine a name for the component. Ensure that it's either:\\n\" +\n '- Assigned to a variable\\n' +\n '- Is an object property\\n' +\n '- Is a prop in a JSX element\\n'\n );\n }\n }\n\n return displayName;\n}\n\nfunction isTagReferenced(path: NodePath): boolean {\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n let isReferenced = true;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n // FIXME: replace with id.isReferencedIdentifier()\n if (id.isIdentifier()) {\n const { referencePaths } = path.scope.getBinding(id.node.name) || {\n referencePaths: [],\n };\n\n isReferenced = referencePaths.length !== 0;\n }\n }\n }\n\n return isReferenced;\n}\n\nconst counters = new WeakMap<IFileContext, number>();\nconst getNextIndex = (state: IFileContext) => {\n const counter = counters.get(state) ?? 0;\n counters.set(state, counter + 1);\n return counter;\n};\n\nexport function getDefinedProcessors(\n imports: IImport[],\n path: NodePath<Program>,\n filename: string | null | undefined,\n options: Pick<StrictOptions, 'tagResolver'>\n): DefinedProcessors {\n const cache = getTraversalCache<DefinedProcessors, NodePath<Program>>(\n path,\n 'getDefinedProcessors'\n );\n\n if (!cache.has(path)) {\n const defined: DefinedProcessors = new Map();\n\n imports.forEach((i) => {\n const [processor, tagSource] = getProcessorForImport(\n i,\n filename,\n options\n );\n const { local } = i;\n if (!processor) {\n return;\n }\n\n let name: string | null = null;\n if (local.isIdentifier()) {\n name = local.node.name;\n }\n\n if (name === null && local.isMemberExpression()) {\n const property = local.get('property');\n const object = local.get('object');\n if (property.isIdentifier() && object.isIdentifier()) {\n name = `${object.node.name}.${property.node.name}`;\n }\n }\n\n if (name === null) {\n return;\n }\n\n defined.set(name, [processor, tagSource]);\n });\n\n cache.set(path, defined);\n }\n\n return cache.get(path)!;\n}\n\nfunction createProcessorInstance(\n definedProcessor: [ProcessorClass, TagSource],\n imports: IImport[],\n path: NodePath<Identifier>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >\n): BaseProcessor | null {\n const cache = getTraversalCache<BaseProcessor | null, Identifier>(\n path,\n 'createProcessorInstance'\n );\n\n if (!cache.has(path.node)) {\n try {\n const builder = getBuilderForIdentifier(\n definedProcessor,\n path,\n imports,\n options\n );\n if (builder) {\n // Increment the index of the style we're processing\n // This is used for slug generation to prevent collision\n // Also used for display name if it couldn't be determined\n const idx = getNextIndex(fileContext);\n\n const displayName = getDisplayName(path, idx, fileContext.filename);\n\n const processor = builder(\n displayName,\n isTagReferenced(path),\n idx,\n options,\n fileContext\n );\n\n cache.set(path.node, processor);\n } else {\n cache.set(path.node, null);\n }\n } catch (e) {\n if (e === BaseProcessor.SKIP) {\n cache.set(path.node, null);\n return null;\n }\n\n if (e instanceof Error) {\n throw buildCodeFrameError(path, e.message);\n }\n\n throw e;\n }\n }\n\n return cache.get(path.node) ?? null;\n}\n\nexport function applyProcessors(\n path: NodePath<Program>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >,\n callback: (processor: BaseProcessor) => void\n) {\n const imports = collectExportsAndImports(path).imports.filter(explicitImport);\n\n const definedProcessors = getDefinedProcessors(\n imports,\n path,\n fileContext.filename,\n options\n );\n\n const usages: {\n identifier: NodePath<Identifier>;\n processor: DefinedProcessor;\n }[] = [];\n\n definedProcessors.forEach((processor, idName) => {\n if (idName.includes('.')) {\n // It's a member expression\n const [object, property] = idName.split('.');\n const objBinding = path.scope.getBinding(object);\n if (!objBinding) {\n return;\n }\n\n objBinding.referencePaths.forEach((p) => {\n const parent = p.parentPath;\n if (!parent?.isMemberExpression()) {\n return;\n }\n\n const identifier = parent.get('property');\n if (identifier.isIdentifier({ name: property })) {\n usages.push({\n identifier,\n processor,\n });\n }\n });\n\n return;\n }\n\n path.scope.getBinding(idName)?.referencePaths.forEach((identifier) => {\n if (identifier.isIdentifier()) {\n usages.push({\n identifier,\n processor,\n });\n }\n });\n });\n\n // The same order, the same slugs\n usages.sort(\n (a, b) => (a.identifier.node.start ?? 0) - (b.identifier.node.start ?? 0)\n );\n\n usages.forEach((usage) => {\n const definedProcessor = usage.processor;\n\n if (!definedProcessor) {\n return;\n }\n\n const instance = createProcessorInstance(\n definedProcessor,\n imports,\n usage.identifier,\n fileContext,\n options\n );\n\n if (instance === null) {\n return;\n }\n\n callback(instance);\n });\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,GAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,oBAAA,GAAAH,OAA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AAI,CAAC;UACV4K,UAAU;UACVtH;QACF,CAAC,CAAC;MACJ;IACF,CAAC,CAAC;EACJ,CAAC,CAAC;;EAEF;EACAgH,MAAM,CAACO,IAAI,CACT,CAACC,CAAC,EAAEC,CAAC;IAAA,IAAAC,qBAAA,EAAAC,qBAAA;IAAA,OAAK,EAAAD,qBAAA,GAACF,CAAC,CAACF,UAAU,CAAC5G,IAAI,CAACkH,KAAK,cAAAF,qBAAA,cAAAA,qBAAA,GAAI,CAAC,MAAAC,qBAAA,GAAKF,CAAC,CAACH,UAAU,CAAC5G,IAAI,CAACkH,KAAK,cAAAD,qBAAA,cAAAA,qBAAA,GAAI,CAAC,CAAC;EAAA,CAC3E,CAAC;EAEDX,MAAM,CAACb,OAAO,CAAE0B,KAAK,IAAK;IACxB,MAAM3H,gBAAgB,GAAG2H,KAAK,CAAC7H,SAAS;IAExC,IAAI,CAACE,gBAAgB,EAAE;MACrB;IACF;IAEA,MAAM4H,QAAQ,GAAGzB,uBAAuB,CACtCnG,gBAAgB,EAChBC,OAAO,EACP0H,KAAK,CAACP,UAAU,EAChBhB,WAAW,EACX1G,OACF,CAAC;IAED,IAAIkI,QAAQ,KAAK,IAAI,EAAE;MACrB;IACF;IAEAlB,QAAQ,CAACkB,QAAQ,CAAC;EACpB,CAAC,CAAC;AACJ"}
1
+ {"version":3,"file":"getTagProcessor.js","names":["_fs","require","_path","_core","_helperModuleImports","_processorUtils","_shared","_collectExportsAndImports","_collectTemplateDependencies","_getSource","_isNotNull","_scopeHelpers","_traversalCache","last","arr","length","zip","arr1","arr2","result","i","push","buildCodeFrameError","path","message","Error","definedTagsCache","Map","getDefinedTagsFromPackage","pkgName","filename","_packageJSON$wywInJ","has","get","packageJSONPath","findPackageJSON","undefined","packageDir","dirname","packageJSON","JSON","parse","readFileSync","definedTags","tags","normalizedTags","Object","entries","reduce","acc","key","value","startsWith","join","resolve","paths","set","isValidProcessorClass","module","BaseProcessor","constructor","getProcessorFromPackage","packageName","tagName","processorPath","Processor","default","getProcessorFromFile","getProcessorForImport","imported","source","options","_options$tagResolver","tagResolver","customFile","processor","getBuilderForIdentifier","definedProcessor","imports","_tagPath$parentPath","tagSource","tagPath","parentPath","isMemberExpression","property","node","params","prev","current","_current","_current2","_current3","_current4","isSequenceExpression","expressions","isCallExpression","callee","args","cookedArgs","map","arg","buildError","bind","isExpression","type","getSource","extracted","extractExpression","evaluate","filter","isNotNull","object","isIdentifier","computed","name","isStringLiteral","isTaggedTemplateExpression","tag","quasis","expressionValues","collectTemplateDependencies","replacer","replacement","isPure","mutate","p","replaceWith","addComment","importHelpers","addDefaultImport","importedSource","nameHint","addDefault","addNamedImport","addNamed","astService","Proxy","t","target","prop","receiver","Reflect","_tagPath$node$loc","loc","getDisplayName","idx","displayName","parent","findParent","isObjectProperty","isJSXOpeningElement","isVariableDeclarator","toString","keyPath","isJSXIdentifier","id","basename","test","replace","isTagReferenced","isReferenced","referencePaths","scope","getBinding","counters","WeakMap","getNextIndex","state","_counters$get","counter","getDefinedProcessors","cache","getTraversalCache","defined","forEach","local","createProcessorInstance","fileContext","_cache$get","builder","e","SKIP","applyProcessors","callback","collectExportsAndImports","explicitImport","definedProcessors","usages","idName","_path$scope$getBindin","includes","split","objBinding","identifier","sort","a","b","_a$identifier$node$st","_b$identifier$node$st","start","usage","instance"],"sources":["../../src/utils/getTagProcessor.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { basename, dirname, join } from 'path';\n\nimport { types as t } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport type { NodePath } from '@babel/traverse';\nimport type {\n Expression,\n Identifier,\n MemberExpression,\n Program,\n SourceLocation,\n} from '@babel/types';\n\nimport { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Param,\n Params,\n IFileContext,\n TagSource,\n} from '@wyw-in-js/processor-utils';\nimport { findPackageJSON } from '@wyw-in-js/shared';\nimport type { ExpressionValue, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { IImport } from './collectExportsAndImports';\nimport {\n collectExportsAndImports,\n explicitImport,\n} from './collectExportsAndImports';\nimport {\n collectTemplateDependencies,\n extractExpression,\n} from './collectTemplateDependencies';\nimport { getSource } from './getSource';\nimport { isNotNull } from './isNotNull';\nimport { mutate } from './scopeHelpers';\nimport { getTraversalCache } from './traversalCache';\n\ntype BuilderArgs = ConstructorParameters<typeof BaseProcessor> extends [\n Params,\n TagSource,\n typeof t,\n SourceLocation | null,\n (replacement: Expression, isPure: boolean) => void,\n ...infer T,\n]\n ? T\n : never;\n\ntype Builder = (...args: BuilderArgs) => BaseProcessor;\n\ntype DefinedProcessor = [ProcessorClass, TagSource];\ntype DefinedProcessors = Map<string, DefinedProcessor>;\n\nexport type ProcessorClass = new (\n ...args: ConstructorParameters<typeof BaseProcessor>\n) => BaseProcessor;\n\nconst last = <T>(arr: T[]): T | undefined => arr[arr.length - 1];\n\nfunction zip<T1, T2>(arr1: T1[], arr2: T2[]) {\n const result: (T1 | T2)[] = [];\n for (let i = 0; i < arr1.length; i++) {\n result.push(arr1[i]);\n if (arr2[i]) result.push(arr2[i]);\n }\n\n return result;\n}\n\nfunction buildCodeFrameError(path: NodePath, message: string): Error {\n try {\n return path.buildCodeFrameError(message);\n } catch {\n return new Error(message);\n }\n}\n\nconst definedTagsCache = new Map<string, Record<string, string> | undefined>();\nconst getDefinedTagsFromPackage = (\n pkgName: string,\n filename: string | null | undefined\n): Record<string, string> | undefined => {\n if (definedTagsCache.has(pkgName)) {\n return definedTagsCache.get(pkgName);\n }\n\n const packageJSONPath = findPackageJSON(pkgName, filename);\n if (!packageJSONPath) {\n return undefined;\n }\n\n const packageDir = dirname(packageJSONPath);\n const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'));\n const definedTags: Record<string, string> | undefined =\n packageJSON['wyw-in-js']?.tags;\n\n const normalizedTags = definedTags\n ? Object.entries(definedTags).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: value.startsWith('.')\n ? join(packageDir, value)\n : require.resolve(value, { paths: [packageDir] }),\n }),\n {} as Record<string, string>\n )\n : undefined;\n\n definedTagsCache.set(pkgName, normalizedTags);\n\n return normalizedTags;\n};\n\nfunction isValidProcessorClass(module: unknown): module is ProcessorClass {\n return module instanceof BaseProcessor.constructor;\n}\n\nfunction getProcessorFromPackage(\n packageName: string,\n tagName: string,\n filename: string | null | undefined\n): ProcessorClass | null {\n const definedTags = getDefinedTagsFromPackage(packageName, filename);\n const processorPath = definedTags?.[tagName];\n if (!processorPath) {\n return null;\n }\n\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nfunction getProcessorFromFile(processorPath: string): ProcessorClass | null {\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nexport function getProcessorForImport(\n { imported, source }: IImport,\n filename: string | null | undefined,\n options: Pick<StrictOptions, 'tagResolver'>\n): [ProcessorClass | null, TagSource] {\n const tagResolver = options.tagResolver ?? (() => null);\n\n const customFile = tagResolver(source, imported);\n const processor = customFile\n ? getProcessorFromFile(customFile)\n : getProcessorFromPackage(source, imported, filename);\n return [processor, { imported, source }];\n}\n\nfunction getBuilderForIdentifier(\n definedProcessor: DefinedProcessor,\n path: NodePath<Identifier>,\n imports: IImport[],\n options: Pick<StrictOptions, 'evaluate'>\n): Builder | null {\n const [Processor, tagSource] = definedProcessor;\n let tagPath: NodePath<Identifier | MemberExpression> = path;\n if (tagPath.parentPath?.isMemberExpression({ property: tagPath.node })) {\n tagPath = tagPath.parentPath;\n }\n\n if (!Processor || !tagSource || !tagPath) {\n return null;\n }\n\n const params: Param[] = [['callee', tagPath.node]];\n let prev: NodePath = tagPath;\n let current: NodePath | null = tagPath.parentPath;\n while (current && current !== path) {\n if (\n current?.isSequenceExpression() &&\n last(current.node.expressions) === prev.node\n ) {\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isCallExpression({ callee: prev.node })) {\n const args = current.get('arguments');\n const cookedArgs = args\n .map((arg) => {\n const buildError = arg.buildCodeFrameError.bind(arg);\n if (!arg.isExpression()) {\n throw buildError(`Unexpected type of an argument ${arg.type}`);\n }\n const source = getSource(arg);\n const extracted = extractExpression(arg, options.evaluate, imports);\n return {\n ...extracted,\n source,\n buildCodeFrameError: buildError,\n } as ExpressionValue;\n })\n .filter(isNotNull);\n\n params.push(['call', ...cookedArgs]);\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isMemberExpression({ object: prev.node })) {\n const property = current.get('property');\n if (property.isIdentifier() && !current.node.computed) {\n params.push(['member', property.node.name]);\n } else if (property.isStringLiteral()) {\n params.push(['member', property.node.value]);\n } else {\n throw property.buildCodeFrameError(`Unexpected type of a property`);\n }\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isTaggedTemplateExpression({ tag: prev.node })) {\n const [quasis, expressionValues] = collectTemplateDependencies(\n current,\n options.evaluate\n );\n params.push(['template', zip(quasis, expressionValues)]);\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n break;\n }\n\n const replacer = (\n replacement: Expression | ((tagPath: NodePath) => Expression),\n isPure: boolean\n ) => {\n mutate(prev, (p) => {\n p.replaceWith(\n typeof replacement === 'function' ? replacement(p) : replacement\n );\n if (isPure) {\n p.addComment('leading', '#__PURE__');\n }\n });\n };\n\n const importHelpers = {\n addDefaultImport: (importedSource: string, nameHint?: string) =>\n addDefault(path, importedSource, { nameHint }),\n addNamedImport: (\n name: string,\n importedSource: string,\n nameHint: string = name\n ) => addNamed(path, name, importedSource, { nameHint }),\n };\n\n type AstService = typeof t & typeof importHelpers;\n\n const astService = new Proxy<AstService>(t as AstService, {\n get(target, prop, receiver) {\n if (prop in importHelpers) {\n return importHelpers[prop as keyof typeof importHelpers];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n });\n\n return (...args: BuilderArgs) =>\n new Processor(\n params,\n tagSource,\n astService,\n tagPath.node.loc ?? null,\n replacer,\n ...args\n );\n}\n\nfunction getDisplayName(\n path: NodePath<Identifier>,\n idx: number,\n filename?: string | null\n): string {\n let displayName: string | undefined;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isObjectProperty()) {\n if ('name' in parent.node.key) {\n displayName = parent.node.key.name;\n } else if ('value' in parent.node.key) {\n displayName = parent.node.key.value.toString();\n } else {\n const keyPath = parent.get('key');\n displayName = getSource(keyPath);\n }\n } else if (parent.isJSXOpeningElement()) {\n const name = parent.get('name');\n if (name.isJSXIdentifier()) {\n displayName = name.node.name;\n }\n } else if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n if (id.isIdentifier()) {\n displayName = id.node.name;\n }\n }\n }\n\n if (!displayName) {\n // Try to derive the path from the filename\n displayName = basename(filename ?? 'unknown');\n\n if (filename && /^index\\.[a-z\\d]+$/.test(displayName)) {\n // If the file name is 'index', better to get name from parent folder\n displayName = basename(dirname(filename));\n }\n\n // Remove the file extension\n displayName = displayName.replace(/\\.[a-z\\d]+$/, '');\n\n if (displayName) {\n displayName += idx;\n } else {\n throw new Error(\n \"Couldn't determine a name for the component. Ensure that it's either:\\n\" +\n '- Assigned to a variable\\n' +\n '- Is an object property\\n' +\n '- Is a prop in a JSX element\\n'\n );\n }\n }\n\n return displayName;\n}\n\nfunction isTagReferenced(path: NodePath): boolean {\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n let isReferenced = true;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n // FIXME: replace with id.isReferencedIdentifier()\n if (id.isIdentifier()) {\n const { referencePaths } = path.scope.getBinding(id.node.name) || {\n referencePaths: [],\n };\n\n isReferenced = referencePaths.length !== 0;\n }\n }\n }\n\n return isReferenced;\n}\n\nconst counters = new WeakMap<IFileContext, number>();\nconst getNextIndex = (state: IFileContext) => {\n const counter = counters.get(state) ?? 0;\n counters.set(state, counter + 1);\n return counter;\n};\n\nexport function getDefinedProcessors(\n imports: IImport[],\n path: NodePath<Program>,\n filename: string | null | undefined,\n options: Pick<StrictOptions, 'tagResolver'>\n): DefinedProcessors {\n const cache = getTraversalCache<DefinedProcessors, NodePath<Program>>(\n path,\n 'getDefinedProcessors'\n );\n\n if (!cache.has(path)) {\n const defined: DefinedProcessors = new Map();\n\n imports.forEach((i) => {\n const [processor, tagSource] = getProcessorForImport(\n i,\n filename,\n options\n );\n const { local } = i;\n if (!processor) {\n return;\n }\n\n let name: string | null = null;\n if (local.isIdentifier()) {\n name = local.node.name;\n }\n\n if (name === null && local.isMemberExpression()) {\n const property = local.get('property');\n const object = local.get('object');\n if (property.isIdentifier() && object.isIdentifier()) {\n name = `${object.node.name}.${property.node.name}`;\n }\n }\n\n if (name === null) {\n return;\n }\n\n defined.set(name, [processor, tagSource]);\n });\n\n cache.set(path, defined);\n }\n\n return cache.get(path)!;\n}\n\nfunction createProcessorInstance(\n definedProcessor: [ProcessorClass, TagSource],\n imports: IImport[],\n path: NodePath<Identifier>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >\n): BaseProcessor | null {\n const cache = getTraversalCache<BaseProcessor | null, Identifier>(\n path,\n 'createProcessorInstance'\n );\n\n if (!cache.has(path.node)) {\n try {\n const builder = getBuilderForIdentifier(\n definedProcessor,\n path,\n imports,\n options\n );\n if (builder) {\n // Increment the index of the style we're processing\n // This is used for slug generation to prevent collision\n // Also used for display name if it couldn't be determined\n const idx = getNextIndex(fileContext);\n\n const displayName = getDisplayName(path, idx, fileContext.filename);\n\n const processor = builder(\n displayName,\n isTagReferenced(path),\n idx,\n options,\n fileContext\n );\n\n cache.set(path.node, processor);\n } else {\n cache.set(path.node, null);\n }\n } catch (e) {\n if (e === BaseProcessor.SKIP) {\n cache.set(path.node, null);\n return null;\n }\n\n if (e instanceof Error) {\n throw buildCodeFrameError(path, e.message);\n }\n\n throw e;\n }\n }\n\n return cache.get(path.node) ?? null;\n}\n\nexport function applyProcessors(\n path: NodePath<Program>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >,\n callback: (processor: BaseProcessor) => void\n) {\n const imports = collectExportsAndImports(path).imports.filter(explicitImport);\n\n const definedProcessors = getDefinedProcessors(\n imports,\n path,\n fileContext.filename,\n options\n );\n\n const usages: {\n identifier: NodePath<Identifier>;\n processor: DefinedProcessor;\n }[] = [];\n\n definedProcessors.forEach((processor, idName) => {\n if (idName.includes('.')) {\n // It's a member expression\n const [object, property] = idName.split('.');\n const objBinding = path.scope.getBinding(object);\n if (!objBinding) {\n return;\n }\n\n objBinding.referencePaths.forEach((p) => {\n const parent = p.parentPath;\n if (!parent?.isMemberExpression()) {\n return;\n }\n\n const identifier = parent.get('property');\n if (identifier.isIdentifier({ name: property })) {\n usages.push({\n identifier,\n processor,\n });\n }\n });\n\n return;\n }\n\n path.scope.getBinding(idName)?.referencePaths.forEach((identifier) => {\n if (identifier.isIdentifier()) {\n usages.push({\n identifier,\n processor,\n });\n }\n });\n });\n\n // The same order, the same slugs\n usages.sort(\n (a, b) => (a.identifier.node.start ?? 0) - (b.identifier.node.start ?? 0)\n );\n\n usages.forEach((usage) => {\n const definedProcessor = usage.processor;\n\n if (!definedProcessor) {\n return;\n }\n\n const instance = createProcessorInstance(\n definedProcessor,\n imports,\n usage.identifier,\n fileContext,\n options\n );\n\n if (instance === null) {\n return;\n }\n\n callback(instance);\n });\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,GAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,O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AAEmB,UAAU,IAAK;MACpE,IAAIA,UAAU,CAACjF,YAAY,CAAC,CAAC,EAAE;QAC7B2E,MAAM,CAACtK,IAAI,CAAC;UACV4K,UAAU;UACVtH;QACF,CAAC,CAAC;MACJ;IACF,CAAC,CAAC;EACJ,CAAC,CAAC;;EAEF;EACAgH,MAAM,CAACO,IAAI,CACT,CAACC,CAAC,EAAEC,CAAC;IAAA,IAAAC,qBAAA,EAAAC,qBAAA;IAAA,OAAK,EAAAD,qBAAA,GAACF,CAAC,CAACF,UAAU,CAAC5G,IAAI,CAACkH,KAAK,cAAAF,qBAAA,cAAAA,qBAAA,GAAI,CAAC,MAAAC,qBAAA,GAAKF,CAAC,CAACH,UAAU,CAAC5G,IAAI,CAACkH,KAAK,cAAAD,qBAAA,cAAAA,qBAAA,GAAI,CAAC,CAAC;EAAA,CAC3E,CAAC;EAEDX,MAAM,CAACb,OAAO,CAAE0B,KAAK,IAAK;IACxB,MAAM3H,gBAAgB,GAAG2H,KAAK,CAAC7H,SAAS;IAExC,IAAI,CAACE,gBAAgB,EAAE;MACrB;IACF;IAEA,MAAM4H,QAAQ,GAAGzB,uBAAuB,CACtCnG,gBAAgB,EAChBC,OAAO,EACP0H,KAAK,CAACP,UAAU,EAChBhB,WAAW,EACX1G,OACF,CAAC;IAED,IAAIkI,QAAQ,KAAK,IAAI,EAAE;MACrB;IACF;IAEAlB,QAAQ,CAACkB,QAAQ,CAAC;EACpB,CAAC,CAAC;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wyw-in-js/transform",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "dependencies": {
5
5
  "@babel/core": "^7.23.5",
6
6
  "@babel/generator": "^7.23.5",
@@ -15,8 +15,8 @@
15
15
  "source-map": "^0.7.4",
16
16
  "stylis": "^4.3.0",
17
17
  "ts-invariant": "^0.10.3",
18
- "@wyw-in-js/processor-utils": "0.5.0",
19
- "@wyw-in-js/shared": "0.5.0"
18
+ "@wyw-in-js/processor-utils": "0.5.2",
19
+ "@wyw-in-js/shared": "0.5.2"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@babel/plugin-syntax-typescript": "^7.23.3",
@@ -37,10 +37,10 @@
37
37
  "glob": "^10.3.10",
38
38
  "strip-ansi": "^5.2.0",
39
39
  "typescript": "^5.2.2",
40
- "@wyw-in-js/babel-config": "0.5.0",
41
- "@wyw-in-js/eslint-config": "0.5.0",
42
- "@wyw-in-js/jest-preset": "0.5.0",
43
- "@wyw-in-js/ts-config": "0.5.0"
40
+ "@wyw-in-js/babel-config": "0.5.2",
41
+ "@wyw-in-js/eslint-config": "0.5.2",
42
+ "@wyw-in-js/jest-preset": "0.5.2",
43
+ "@wyw-in-js/ts-config": "0.5.2"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=16.0.0"
package/types/module.d.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  /// <reference types="node" />
14
14
  /// <reference types="debug" />
15
15
  import NativeModule from 'module';
16
- import type { Debugger } from '@wyw-in-js/shared';
16
+ import { type Debugger } from '@wyw-in-js/shared';
17
17
  import './utils/dispose-polyfill';
18
18
  import { Entrypoint } from './transform/Entrypoint';
19
19
  import type { IEntrypointDependency } from './transform/Entrypoint.types';
package/types/module.js CHANGED
@@ -21,6 +21,7 @@ const module_1 = __importDefault(require("module"));
21
21
  const path_1 = __importDefault(require("path"));
22
22
  const vm_1 = __importDefault(require("vm"));
23
23
  const ts_invariant_1 = require("ts-invariant");
24
+ const shared_1 = require("@wyw-in-js/shared");
24
25
  require("./utils/dispose-polyfill");
25
26
  const Entrypoint_1 = require("./transform/Entrypoint");
26
27
  const Entrypoint_helpers_1 = require("./transform/Entrypoint.helpers");
@@ -132,7 +133,9 @@ class Module {
132
133
  this.services = services;
133
134
  this.moduleImpl = moduleImpl;
134
135
  this.cache = services.cache;
135
- this.#entrypointRef = new WeakRef(entrypoint);
136
+ this.#entrypointRef = (0, shared_1.isFeatureEnabled)(services.options.pluginOptions.features, 'useWeakRefInEval', entrypoint.name)
137
+ ? new WeakRef(entrypoint)
138
+ : entrypoint;
136
139
  this.idx = entrypoint.idx;
137
140
  this.id = entrypoint.name;
138
141
  this.filename = entrypoint.name;
@@ -157,7 +160,9 @@ class Module {
157
160
  this.debug('the whole exports was overridden with %O', value);
158
161
  }
159
162
  get entrypoint() {
160
- const entrypoint = this.#entrypointRef.deref();
163
+ const entrypoint = this.#entrypointRef instanceof WeakRef
164
+ ? this.#entrypointRef.deref()
165
+ : this.#entrypointRef;
161
166
  (0, ts_invariant_1.invariant)(entrypoint, `Module ${this.idx} is disposed`);
162
167
  return entrypoint;
163
168
  }
@@ -41,6 +41,7 @@ function loadWywOptions(overrides = defaultOverrides) {
41
41
  happyDOM: true,
42
42
  softErrors: false,
43
43
  useBabelConfigs: true,
44
+ useWeakRefInEval: true,
44
45
  };
45
46
  const options = {
46
47
  displayName: false,
@@ -156,7 +156,7 @@ function getBuilderForIdentifier(definedProcessor, path, imports, options) {
156
156
  }
157
157
  const replacer = (replacement, isPure) => {
158
158
  (0, scopeHelpers_1.mutate)(prev, (p) => {
159
- p.replaceWith(replacement);
159
+ p.replaceWith(typeof replacement === 'function' ? replacement(p) : replacement);
160
160
  if (isPure) {
161
161
  p.addComment('leading', '#__PURE__');
162
162
  }