fix: normalize PURE annotations for Vite 8 and Rolldown - #2766
Conversation
Rolldown cannot apply PURE annotations to primitive literals and emits INVALID_ANNOTATION warnings when consuming the Vite 8 module build. Remove the invalid markers and extend bundle checks to prevent regressions. Fixes microsoft#2764. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Prefer concise names that describe the change and avoid generic investigation or issue-only branch names. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Honor the prior maintainer direction from microsoft#2737 and microsoft#2744 by retaining parenthesized PURE markers in source. Remove ineffective annotations from primitive literals only when normalizing emitted bundles so Rolldown can consume dist-es5 without warnings. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Parse generated JavaScript so PURE annotations are retained only for call and new expressions. Remove invalid annotations from every other expression without altering strings or ordinary comments, and run comprehensive parser fixtures in CI. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The new PURE normalization test file contains invalid JS/incorrect expected strings that will fail parsing/assertions, and the new acorn@^8.18.0 dependency likely requires lockfile updates for Rush/pnpm consistency.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the build tooling to normalize /*#__PURE__*/ / /*@__PURE__*/ annotations in generated ES5 module output so newer bundlers (Vite 8 / Rolldown) don’t emit [INVALID_ANNOTATION] warnings, while preserving valid annotations on call/new expressions.
Changes:
- Replaces regex-based PURE spacing normalization with AST-based parsing (Acorn) to canonicalize valid annotations and remove invalid ones.
- Adds a dedicated Node test (
tools/pureAnnotations.test.mjs) and wires it intonpm test. - Extends size tests to detect PURE annotations applied to literals (a known invalid form for Rolldown).
File summaries
| File | Description |
|---|---|
| tools/pureAnnotations.test.mjs | Adds normalization test coverage for many expression types and idempotency. |
| tools/pureAnnotations.mjs | Implements AST-driven PURE annotation normalization using Acorn tokens/comments. |
| tools/grunt-tasks/fixPureAnnotations.js | Updates the Grunt task to use the shared normalizer and handle failures. |
| shared/AppInsightsCore/Tests/Unit/src/ai/AppInsightsCoreSize.Tests.ts | Tightens output validation by detecting PURE-on-literal patterns. |
| AISKU/Tests/Unit/src/AISKUSize.Tests.ts | Same PURE validity checks for AISKU bundle outputs. |
| package.json | Adds test:pure-annotations and the acorn devDependency. |
| .github/copilot-instructions.md | Adds a repository branch naming convention guideline. |
Review details
Suppressed comments (4)
tools/pureAnnotations.test.mjs:50
- These expected strings are missing the opening
/*of the PURE comment;canonicalizePureAnnotations()emits/*#__PURE__*/..., so the assertions will fail.
{
expected: "var value = /*#__PURE__*/namespace.factory();",
input: "var value = /* #__PURE__ */ namespace.factory();"
},
tools/pureAnnotations.test.mjs:54
- This expected output is missing the opening
/*for the PURE comment, so the assertion won't match the normalized output.
{
expected: "var value = /*#__PURE__*/(function () {})();",
input: "var value = /* #__PURE__ */ (function () {})();"
},
tools/pureAnnotations.test.mjs:58
- This expected output is missing the opening
/*for the PURE comment, so the assertion won't match the normalized output.
{
expected: "var value = /*#__PURE__*/(0, factory)();",
input: "var value = /* #__PURE__ */ (0, factory)();"
},
tools/grunt-tasks/fixPureAnnotations.js:80
- The success log still says "Canonicalized" even though the task now removes invalid annotations as well; updating wording to "Normalized" would better reflect what happened.
grunt.log.ok("Canonicalized PURE annotations: checked " + filesChecked + " file(s), updated " + filesChanged + " file(s).");
- Files reviewed: 7/7 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Fixes invalid PURE annotation warnings emitted by Vite 8/Rolldown when consuming the SDK's
dist-es5modules.The generated JavaScript is now parsed so that:
newexpressions are preserved and canonicalized.dist/es5and TypeScriptdist-es5outputs use the same normalization.Testing
Added coverage for literals, arrays, objects, functions, classes, regexes, templates, unary/binary/conditional expressions, calls, constructors, IIFEs, optional calls, multiline ESM, comments, strings, idempotency, and invalid JavaScript.
Fixes #2763
Fixes #2764