fix: chained call - #157
Conversation
|
|
|
Confirming this fixes a real bug. The fixture doesn't cover enough of it, though. Here's the case I hit, on // macros.js
export const answer = () => 42// main.js
import { answer } from './macros.js' with { type: 'macro' }
export default [answer()].filter(Boolean)// vite.config.mjs
import macros from 'unplugin-macros/vite'
export default {
plugins: [macros()],
build: { minify: false, lib: { entry: 'main.js', formats: ['es'], fileName: 'out' } },
}The macro is silently ignored. var main_default = [answer()].filter(Boolean);The import is stripped but the call is left behind, so importing that module throws The reason import { getRandom } from './macros/rand' with { type: 'macro' }
const values = [getRandom()].filter(Boolean)
const joined = [getRandom(), getRandom()].map((value) => value).join(',')I checked that it fails on the original ordering and passes with your change. One other thing worth raising. The silence is what made this expensive to track down. |
|
If anyone's blocked on this, I published this branch as pnpm add -D "unplugin-macros@npm:@ariesclark/unplugin-macros@0.20.3" |
vite-plugin-babel parsed and regenerated every file it matched, including node_modules, which Babel reported as deoptimised for react-dom and @formatjs/intl-datetimeformat. unplugin-macros evaluates macros without a Babel pass, and `ms` can be imported directly instead of through the ms.macro wrapper, so @types/ms now checks the duration strings. Import attributes require a module target above ES2022, hence the tsconfig bump; ESNext is also the correct pairing for moduleResolution: bundler. babel-plugin-dev-expression is dropped with nothing to replace it: it only stripped invariant() messages in production, and the codebase has no __DEV__ or warning() calls. unplugin-macros is pinned to a fork that carries unplugin/unplugin-macros#157, which fixes macros being silently dropped inside a chained call's object (`[ms("30s")].filter(Boolean)`). Revert to the upstream package once that lands.
Description
CallExpression, it was immediately skipped before checking whether it's a macro function or not.Linked Issues