Skip to content

Commit d7349e7

Browse files
zernoniaclaude
andauthored
fix(core): prevent /*#__PURE__*/ annotation inside function declarations (#2585)
The pureAnnotationPlugin regex matched `createContext(` inside function declarations like `function createContext(...)`, inserting the annotation between the `function` keyword and the name. This caused Rollup/Vite to emit a warning about uninterpretable annotations. Added a negative lookbehind `(?<!function\s)` to skip function declarations, so only actual call sites get annotated. Fixes #2579 Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5cc56e0 commit d7349e7

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

packages/core/tsdown.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { defineConfig } from 'tsdown'
33

44
// Match `defineComponent(`, `createContext(`, `reactive(` at word boundaries,
55
// skipping calls already preceded by a PURE annotation or prefixed with a
6-
// word character (e.g. _defineComponent).
7-
const PURE_PATTERN = /(?<=^|[^.\w$])(defineComponent|createContext|reactive)\s*\(/g
6+
// word character (e.g. _defineComponent), or preceded by `function` keyword
7+
// (function declarations should not be annotated).
8+
const PURE_PATTERN = /(?<!function\s)(?<=^|[^.\w$])(defineComponent|createContext|reactive)\s*\(/g
89
const ALREADY_PURE = /\/\*\s*[#@]__PURE__\s*\*\/\s*$/
910
const PATH_SEP = /[\\/]/g
1011

0 commit comments

Comments
 (0)